/
file-system-create-symlink.json
40 lines (40 loc) · 3.15 KB
/
file-system-create-symlink.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
{
"Id": "f0cae939-caef-4979-93ac-6c9b3a3c4986",
"Name": "File System - Create Symlink",
"Description": "Creates a Symbolic Link",
"ActionType": "Octopus.Script",
"Version": 23,
"Properties": {
"Octopus.Action.Script.ScriptBody": "function New-Symlink {\n <#\n .SYNOPSIS\n Creates a symbolic link.\n #>\n param (\n [Parameter(Position=0, Mandatory=$true)]\n [string] $Link,\n [Parameter(Position=1, Mandatory=$true)]\n [string] $Target\n )\n\n Write-Host \"New-Symlink $Link to $Target\"\n \n Invoke-MKLINK -Link $Link -Target $Target\n}\n\nfunction Invoke-MKLINK {\n <#\n .SYNOPSIS\n Creates a symbolic link.\n #>\n param (\n [Parameter(Position=0, Mandatory=$true)]\n [string] $Link,\n [Parameter(Position=1, Mandatory=$true)]\n [string] $Target\n )\n \n # Resolve the paths incase a relative path was passed in.\n $Link = (Force-Resolve-Path $Link)\n $Target = (Force-Resolve-Path $Target)\n\n # Ensure target exists.\n if (-not(Test-Path $Target)) {\n throw \"Target does not exist.`nTarget: $Target\"\n }\n\n # Ensure link does not exist.\n if (Test-Path $Link) {\n Write-Host \"A file or directory already exists at the link path.`nLink: $Link\"\n return\n }\n\n $isDirectory = (Get-Item $Target).PSIsContainer\n\n # Capture the MKLINK output so we can return it properly.\n # Includes a redirect of STDERR to STDOUT so we can capture it as well.\n $output = cmd /c mklink /D `\"$Link`\" `\"$Target`\" 2>&1\n \n Write-Host \"output : $output\"\n if ($lastExitCode -ne 0) {\n Write-Host \"MKLINK failed. Exit code: $lastExitCode`n$output\"\n throw \"MKLINK failed. Exit code: $lastExitCode`n$output\"\n }\n else {\n Write-Output $output\n }\n}\n\nfunction Force-Resolve-Path {\n <#\n .SYNOPSIS\n Calls Resolve-Path but works for files that don't exist.\n .REMARKS\n From http://devhawk.net/2010/01/21/fixing-powershells-busted-resolve-path-cmdlet/\n #>\n param (\n [string] $FileName\n )\n \n $FileName = Resolve-Path $FileName -ErrorAction SilentlyContinue `\n -ErrorVariable _frperror\n if (-not($FileName)) {\n $FileName = $_frperror[0].TargetObject\n }\n \n return $FileName\n}\n\nNew-Symlink $link_path $target_path\n\n\n",
"Octopus.Action.Script.Syntax": "PowerShell"
},
"SensitiveProperties": {},
"Parameters": [
{
"Name": "link_path",
"Label": "LinkPath",
"HelpText": null,
"DefaultValue": null,
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
}
},
{
"Name": "target_path",
"Label": "TargetPath",
"HelpText": null,
"DefaultValue": null,
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
}
}
],
"LastModifiedOn": "2014-08-26T15:58:31.623+00:00",
"LastModifiedBy": "diegoavanzini",
"$Meta": {
"ExportedAt": "2014-08-26T15:58:34.242+00:00",
"OctopusVersion": "2.5.7.384",
"Type": "ActionTemplate"
},
"Category": "filesystem"
}