Skip to content

Instantly share code, notes, and snippets.

@Wesley-Lomax
Last active July 3, 2017 10:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Wesley-Lomax/a4d622658f2ce7346769ddeb84ed8376 to your computer and use it in GitHub Desktop.
Save Wesley-Lomax/a4d622658f2ce7346769ddeb84ed8376 to your computer and use it in GitHub Desktop.
Move Unicorn items out of webroot into data folder with Octopus Step
$ErrorActionPreference = 'Continue'
$dataFolder = $OctopusParameters['data.folder']
$websiteFolder = $OctopusParameters['website.folder']
Write-Output "dataFolder: " $dataFolder
Write-Output "websiteFolder: " $websiteFolder
if((Test-Path -Path $dataFolder\Unicorn )){
Write-Output "Owning : $dataFolder\Unicorn"
takeown.exe /A /R /F $dataFolder\Unicorn /D Y
Write-Output "Resetting Permissions : $dataFolder\Unicorn"
icacls.exe $dataFolder\Unicorn /grant RCNLON\svr.Octopus:F /T /Q /C
Write-Output "Clearing : $dataFolder\Unicorn"
Get-ChildItem -Path "$dataFolder\Unicorn\*" -Recurse | Remove-Item -Force -Recurse
}
Write-Output "copy-item -path $websiteFolder\Unicorn -destination $dataFolder\Unicorn -recurse -force"
copy-item -path $websiteFolder\Content\Unicorn\* -destination $dataFolder\Unicorn -recurse -force -ErrorAction SilentlyContinue
Write-Output "Deleting $websiteFolder\Content\Unicorn"
Get-ChildItem -Path "$websiteFolder\Content\Unicorn\*" -Recurse -ErrorAction Ignore | Remove-Item -Force -Recurse -ErrorAction Ignore
remove-item -path $websiteFolder\Content\Unicorn -Recurse -Force -ErrorAction Ignore
{
"Id": "ActionTemplates-23",
"Name": "Move Unicorn files out of webroot",
"Description": "Moves Unicorn yml files from Website folder to Data folder after nuget deploy",
"ActionType": "Octopus.Script",
"Version": 21,
"Properties": {
"Octopus.Action.Package.NuGetFeedId": "feeds-builtin",
"Octopus.Action.Script.Syntax": "PowerShell",
"Octopus.Action.Script.ScriptSource": "Inline",
"Octopus.Action.RunOnServer": "false",
"Octopus.Action.Script.ScriptBody": "$ErrorActionPreference = 'Continue'\r\n$dataFolder = $OctopusParameters['data.folder']\r\n$websiteFolder = $OctopusParameters['website.folder']\r\n\r\nWrite-Output \"dataFolder: \" $dataFolder\r\nWrite-Output \"websiteFolder: \" $websiteFolder\r\n\r\nif((Test-Path -Path $dataFolder\\Unicorn )){\r\n Write-Output \"Owning : $dataFolder\\Unicorn\"\r\n takeown.exe /A /R /F $dataFolder\\Unicorn /D Y\r\n Write-Output \"Resetting Permissions : $dataFolder\\Unicorn\"\r\n icacls.exe $dataFolder\\Unicorn /grant RCNLON\\svr.Octopus:F /T /Q /C\r\n Write-Output \"Clearing : $dataFolder\\Unicorn\"\r\n Get-ChildItem -Path \"$dataFolder\\Unicorn\\*\" -Recurse | Remove-Item -Force -Recurse\r\n}\r\n\r\nWrite-Output \"copy-item -path $websiteFolder\\Unicorn -destination $dataFolder\\Unicorn -recurse -force\"\r\ncopy-item -path $websiteFolder\\Content\\Unicorn\\* -destination $dataFolder\\Unicorn -recurse -force -ErrorAction SilentlyContinue\r\n\r\nWrite-Output \"Deleting $websiteFolder\\Content\\Unicorn\"\r\nGet-ChildItem -Path \"$websiteFolder\\Content\\Unicorn\\*\" -Recurse -ErrorAction Ignore | Remove-Item -Force -Recurse -ErrorAction Ignore\r\nremove-item -path $websiteFolder\\Content\\Unicorn -Recurse -Force -ErrorAction Ignore"
},
"Parameters": [],
"$Meta": {
"ExportedAt": "2017-07-03T10:35:48.384Z",
"OctopusVersion": "3.3.4",
"Type": "ActionTemplate"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment