Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions step-templates/file-system-restore-directory.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"Id": "ActionTemplates-158",
"Name": "File System - Restore Directory",
"Description": "Restores a folder and it's contents (files and sub-folders).",
"ActionType": "Octopus.Script",
"Version": 1,
"Properties": {
"Octopus.Action.Script.ScriptBody": "$source = $OctopusParameters['Source']\r\n$destination = $OctopusParameters['Destination']\r\n\r\nif(Test-Path $destination)\r\n{\r\n ## Clean the destination folder\r\n Write-Host \"Cleaning $destination\"\r\n Remove-Item $destination -Recurse\r\n}\r\n\r\n## Copy recursively\r\nWrite-Host \"Copying from $source to $destination\"\r\nCopy-Item $source $destination -Recurse",
"Octopus.Action.Script.Syntax": "PowerShell"
},
"SensitiveProperties": {},
"Parameters": [
{
"Name": "Source",
"Label": "Source",
"HelpText": "The source directory where files and folders will be copied from",
"DefaultValue": null,
"DisplaySettings": {}
},
{
"Name": "Destination",
"Label": "Destination folder",
"HelpText": "The Destination where the files will be copied to.",
"DefaultValue": null,
"DisplaySettings": {}
}
],
"$Meta": {
"LastModifiedBy": "joaoasrosa",
"Type": "ActionTemplate"
}
}
6 changes: 3 additions & 3 deletions step-templates/iis-app-create.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"Name": "IIS Application - Create",
"Description": "Create an IIS virtual application (a virtual directory with an application pool)",
"ActionType": "Octopus.Script",
"Version": 16,
"Version": 17,
"Properties": {
"Octopus.Action.Script.ScriptBody": "## --------------------------------------------------------------------------------------\r\n## Input\r\n## --------------------------------------------------------------------------------------\r\n\r\n$virtualPath = $OctopusParameters['VirtualPath']\r\n$physicalPath = $OctopusParameters['PhysicalPath']\r\n$applicationPoolName = $OctopusParameters['ApplicationPoolName']\r\n$parentSite = $OctopusParameters['ParentSite']\r\n$bindingProtocols = $OctopusParameters['BindingProtocols']\r\n$authentication = $OctopusParameters['AuthenticationType']\r\n$requireSSL = $OctopusParameters['RequireSSL']\r\n\r\n$anonymousAuthentication = \"Anonymous\"\r\n$windowsAuthentication = \"Windows\"\r\n$basicAuthentication = \"Basic\"\r\n\r\n## --------------------------------------------------------------------------------------\r\n## Helpers\r\n## --------------------------------------------------------------------------------------\r\n# Helper for validating input parameters\r\nfunction Validate-Parameter($foo, [string[]]$validInput, $parameterName) {\r\n Write-Host \"${parameterName}: ${foo}\"\r\n if (! $foo) {\r\n throw \"$parameterName cannot be empty, please specify a value\"\r\n }\r\n \r\n if ($validInput) {\r\n @($foo) | % { \r\n if ($validInput -notcontains $_) {\r\n throw \"'$_' is not a valid input for '$parameterName'\"\r\n }\r\n } \r\n } \r\n}\r\n\r\n# Helper to run a block with a retry if things go wrong\r\n$maxFailures = 5\r\n$sleepBetweenFailures = Get-Random -minimum 1 -maximum 4\r\nfunction Execute-WithRetry([ScriptBlock] $command) {\r\n\t$attemptCount = 0\r\n\t$operationIncomplete = $true\r\n\r\n\twhile ($operationIncomplete -and $attemptCount -lt $maxFailures) {\r\n\t\t$attemptCount = ($attemptCount + 1)\r\n\r\n\t\tif ($attemptCount -ge 2) {\r\n\t\t\tWrite-Output \"Waiting for $sleepBetweenFailures seconds before retrying...\"\r\n\t\t\tStart-Sleep -s $sleepBetweenFailures\r\n\t\t\tWrite-Output \"Retrying...\"\r\n\t\t}\r\n\r\n\t\ttry {\r\n\t\t\t& $command\r\n\r\n\t\t\t$operationIncomplete = $false\r\n\t\t} catch [System.Exception] {\r\n\t\t\tif ($attemptCount -lt ($maxFailures)) {\r\n\t\t\t\tWrite-Output (\"Attempt $attemptCount of $maxFailures failed: \" + $_.Exception.Message)\r\n\t\t\t\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t throw \"Failed to execute command\"\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n\r\n## --------------------------------------------------------------------------------------\r\n## Configuration\r\n## --------------------------------------------------------------------------------------\r\nValidate-Parameter $virtualPath -parameterName \"Virtual path\"\r\nValidate-Parameter $physicalPath -parameterName \"Physical path\"\r\nValidate-Parameter $applicationPoolName -parameterName \"Application pool\"\r\nValidate-Parameter $parentSite -parameterName \"Parent site\"\r\n\r\n\r\nAdd-PSSnapin WebAdministration -ErrorAction SilentlyContinue\r\nImport-Module WebAdministration -ErrorAction SilentlyContinue\r\n\r\n\r\n## --------------------------------------------------------------------------------------\r\n## Run\r\n## --------------------------------------------------------------------------------------\r\n\r\nWrite-Host \"Getting web site $parentSite\"\r\n# Workaround to bug in Get-WebSite cmdlet which would return all sites\r\n# See http://forums.iis.net/p/1167298/1943273.aspx / http://stackoverflow.com/a/6832577/785750\r\n$site = Get-WebSite | where { $_.Name -eq $parentSite }\r\nif (!$site) {\r\n throw \"The web site '$parentSite' does not exist. Please create the site first.\"\r\n}\r\n\r\n$path = $site.PhysicalPath;\r\n$parts = $virtualPath -split \"[/\\\\]\"\r\n$name = \"\"\r\n\r\nfor ($i = 0; $i -lt $parts.Length; $i++) {\r\n $name = $name + \"/\" + $parts[$i]\r\n $name = $name.TrimStart('/').TrimEnd('/')\r\n if ($i -eq $parts.Length - 1) {\r\n \r\n }\r\n elseif ([string]::IsNullOrEmpty($name) -eq $false -and $name -ne \"/\") {\r\n Write-Host \"Ensuring parent exists: $name\"\r\n \r\n $path = [IO.Path]::Combine($path, $parts[$i])\r\n $app = Get-WebApplication -Name $name -Site $parentSite\r\n\r\n if (!$app) {\r\n $vdir = Get-WebVirtualDirectory -Name $name -site $parentSite\r\n if (!$vdir) {\r\n Write-Verbose \"The application or virtual directory '$name' does not exist\"\r\n if([IO.Directory]::Exists($path) -eq $true)\r\n {\r\n Write-Verbose \"Using physical path '$path' as parent\"\r\n }\r\n else\r\n {\r\n throw \"Failed to ensure parent\"\r\n }\r\n }\r\n else\r\n {\r\n $path = $vdir.PhysicalPath\r\n }\r\n }\r\n else\r\n {\r\n $path = $app.PhysicalPath\r\n }\r\n }\r\n}\r\n\r\n$existing = Get-WebApplication -site $parentSite -Name $name\r\n\r\n\r\nExecute-WithRetry { \r\n if (!$existing) {\r\n Write-Host \"Creating web application '$name'\"\r\n New-WebApplication -Site $parentSite -Name $name -ApplicationPool $applicationPoolName -PhysicalPath $physicalPath\r\n Write-Host \"Web application created\"\r\n } else {\r\n Write-Host \"The web application '$name' already exists. Updating physical path:\"\r\n\r\n Set-ItemProperty IIS:\\Sites\\$parentSite\\$name -name physicalPath -value $physicalPath\r\n Write-Host \"Physical path changed to: $physicalPath\"\r\n\r\n Set-ItemProperty IIS:\\Sites\\$parentSite\\$name -Name ApplicationPool -Value $applicationPoolName\r\n Write-Output \"ApplicationPool changed to: $applicationPoolName\"\r\n }\r\n \r\n Write-Host \"Enabling '$bindingProtocols' protocols\"\r\n Set-ItemProperty IIS:\\Sites\\$parentSite\\$name -name enabledProtocols -value $bindingProtocols\r\n\r\n\t\t$enabledIisAuthenticationOptions = $Authentication -split 's*[,;]s*'\r\n\r\n\tValidate-Parameter $enabledIisAuthenticationOptions -validInput @($anonymousAuthentication, $basicAuthentication, $windowsAuthentication) -parameterName \"IIS Authentication\"\r\n\r\n\t$enableAnonymous = $enabledIisAuthenticationOptions -contains $anonymousAuthentication\r\n\t$enableWindows = $enabledIisAuthenticationOptions -contains $windowsAuthentication\r\n\t$enableBasic = $enabledIisAuthenticationOptions -contains $basicAuthentication\r\n\r\n\ttry {\r\n\r\n\tExecute-WithRetry { \r\n\t\tWrite-Output \"Anonymous authentication enabled: $enableAnonymous\"\r\n\t\tSet-WebConfigurationProperty -filter /system.webServer/security/authentication/anonymousAuthentication -name enabled -value \"$enableAnonymous\" -PSPath IIS:\\ -location $parentSite$virtualPath\r\n\t}\t\r\n\t\r\n\tExecute-WithRetry { \r\n\t\tWrite-Output \"Windows authentication enabled: $enableWindows\"\r\n\t\tSet-WebConfigurationProperty -filter /system.WebServer/security/authentication/windowsAuthentication -name enabled -value \"$enableWindows\" -PSPath IIS:\\ -location $parentSite$virtualPath\r\n\t}\r\n\r\n\tExecute-WithRetry { \r\n\t\tWrite-Output \"Basic authentication enabled: $enableBasic\"\r\n\t\tSet-WebConfigurationProperty -filter /system.webServer/security/authentication/basicAuthentication -name enabled -value \"$enableBasic\" -PSPath IIS:\\ -location $parentSite$virtualPath\r\n\t}\r\n\r\n\t} catch [System.Exception] {\r\n\t\tWrite-Output \"Authentication options could not be set. This can happen when there is a problem with your application's web.config. For example, you might be using a section that requires an extension that is not installed on this web server (such as URL Rewrtiting). It can also happen when you have selected an authentication option and the appropriate IIS module is not installed (for example, for Windows authentication, you need to enable the Windows Authentication module in IIS/Windows first)\"\r\n\t\tthrow\r\n\t}\r\n\r\n Set-WebConfiguration -value \"None\" -filter \"system.webserver/security/access\" -location $parentSite/$virtualPath -PSPath IIS:\\ \r\n if ($requireSSL -ieq \"True\")\r\n {\r\n\t\tWrite-Output \"Require SSL enabled: $requireSSL\"\r\n Set-WebConfiguration -value \"Ssl\" -filter \"system.webserver/security/access\" -location $parentSite/$virtualPath -PSPath IIS:\\ \r\n }\r\n}\r\n",
"Octopus.Action.Script.ScriptBody": "## --------------------------------------------------------------------------------------\r\n## Input\r\n## --------------------------------------------------------------------------------------\r\n\r\n$virtualPath = $OctopusParameters['VirtualPath']\r\n$physicalPath = $OctopusParameters['PhysicalPath']\r\n$applicationPoolName = $OctopusParameters['ApplicationPoolName']\r\n$parentSite = $OctopusParameters['ParentSite']\r\n$bindingProtocols = $OctopusParameters['BindingProtocols']\r\n$authentication = $OctopusParameters['AuthenticationType']\r\n$requireSSL = $OctopusParameters['RequireSSL']\r\n\r\n$anonymousAuthentication = \"Anonymous\"\r\n$windowsAuthentication = \"Windows\"\r\n$basicAuthentication = \"Basic\"\r\n\r\n## --------------------------------------------------------------------------------------\r\n## Helpers\r\n## --------------------------------------------------------------------------------------\r\n# Helper for validating input parameters\r\nfunction Validate-Parameter($foo, [string[]]$validInput, $parameterName) {\r\n Write-Host \"${parameterName}: ${foo}\"\r\n if (! $foo) {\r\n throw \"$parameterName cannot be empty, please specify a value\"\r\n }\r\n \r\n if ($validInput) {\r\n @($foo) | % { \r\n if ($validInput -notcontains $_) {\r\n throw \"'$_' is not a valid input for '$parameterName'\"\r\n }\r\n } \r\n } \r\n}\r\n\r\n# Helper to run a block with a retry if things go wrong\r\n$maxFailures = 5\r\n$sleepBetweenFailures = Get-Random -minimum 1 -maximum 4\r\nfunction Execute-WithRetry([ScriptBlock] $command) {\r\n\t$attemptCount = 0\r\n\t$operationIncomplete = $true\r\n\r\n\twhile ($operationIncomplete -and $attemptCount -lt $maxFailures) {\r\n\t\t$attemptCount = ($attemptCount + 1)\r\n\r\n\t\tif ($attemptCount -ge 2) {\r\n\t\t\tWrite-Output \"Waiting for $sleepBetweenFailures seconds before retrying...\"\r\n\t\t\tStart-Sleep -s $sleepBetweenFailures\r\n\t\t\tWrite-Output \"Retrying...\"\r\n\t\t}\r\n\r\n\t\ttry {\r\n\t\t\t& $command\r\n\r\n\t\t\t$operationIncomplete = $false\r\n\t\t} catch [System.Exception] {\r\n\t\t\tif ($attemptCount -lt ($maxFailures)) {\r\n\t\t\t\tWrite-Output (\"Attempt $attemptCount of $maxFailures failed: \" + $_.Exception.Message)\r\n\t\t\t\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t throw \"Failed to execute command\"\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n\r\n## --------------------------------------------------------------------------------------\r\n## Configuration\r\n## --------------------------------------------------------------------------------------\r\nValidate-Parameter $virtualPath -parameterName \"Virtual path\"\r\nValidate-Parameter $physicalPath -parameterName \"Physical path\"\r\nValidate-Parameter $applicationPoolName -parameterName \"Application pool\"\r\nValidate-Parameter $parentSite -parameterName \"Parent site\"\r\n\r\n\r\nAdd-PSSnapin WebAdministration -ErrorAction SilentlyContinue\r\nImport-Module WebAdministration -ErrorAction SilentlyContinue\r\n\r\n\r\n## --------------------------------------------------------------------------------------\r\n## Run\r\n## --------------------------------------------------------------------------------------\r\n\r\nWrite-Host \"Getting web site $parentSite\"\r\n# Workaround to bug in Get-WebSite cmdlet which would return all sites\r\n# See http://forums.iis.net/p/1167298/1943273.aspx / http://stackoverflow.com/a/6832577/785750\r\n$site = Get-WebSite | where { $_.Name -eq $parentSite }\r\nif (!$site) {\r\n throw \"The web site '$parentSite' does not exist. Please create the site first.\"\r\n}\r\n\r\n$path = $site.PhysicalPath;\r\n$parts = $virtualPath -split \"[/\\\\]\"\r\n$name = \"\"\r\n\r\nfor ($i = 0; $i -lt $parts.Length; $i++) {\r\n $name = $name + \"/\" + $parts[$i]\r\n $name = $name.TrimStart('/').TrimEnd('/')\r\n if ($i -eq $parts.Length - 1) {\r\n \r\n }\r\n elseif ([string]::IsNullOrEmpty($name) -eq $false -and $name -ne \"/\") {\r\n Write-Host \"Ensuring parent exists: $name\"\r\n \r\n $path = [IO.Path]::Combine($path, $parts[$i])\r\n $app = Get-WebApplication -Name $name -Site $parentSite\r\n\r\n if (!$app) {\r\n $vdir = Get-WebVirtualDirectory -Name $name -site $parentSite\r\n if (!$vdir) {\r\n Write-Verbose \"The application or virtual directory '$name' does not exist\"\r\n if([IO.Directory]::Exists($path) -eq $true)\r\n {\r\n Write-Verbose \"Using physical path '$path' as parent\"\r\n }\r\n else\r\n {\r\n throw \"Failed to ensure parent\"\r\n }\r\n }\r\n else\r\n {\r\n $path = $vdir.PhysicalPath\r\n }\r\n }\r\n else\r\n {\r\n $path = $app.PhysicalPath\r\n }\r\n }\r\n}\r\n\r\n$existing = Get-WebApplication -site $parentSite -Name $name\r\n\r\n\r\nExecute-WithRetry { \r\n ## Check if the physical path exits\r\n if(!(Test-Path -Path $physicalPath)) {\r\n Write-Host \"Creating physical path '$physicalPath'\"\r\n New-Item -ItemType directory -Path $physicalPath\r\n }\r\n\r\n if (!$existing) {\r\n Write-Host \"Creating web application '$name'\"\r\n New-WebApplication -Site $parentSite -Name $name -ApplicationPool $applicationPoolName -PhysicalPath $physicalPath\r\n Write-Host \"Web application created\"\r\n } else {\r\n Write-Host \"The web application '$name' already exists. Updating physical path:\"\r\n\r\n Set-ItemProperty IIS:\\Sites\\$parentSite\\$name -name physicalPath -value $physicalPath\r\n Write-Host \"Physical path changed to: $physicalPath\"\r\n\r\n Set-ItemProperty IIS:\\Sites\\$parentSite\\$name -Name ApplicationPool -Value $applicationPoolName\r\n Write-Output \"ApplicationPool changed to: $applicationPoolName\"\r\n }\r\n \r\n Write-Host \"Enabling '$bindingProtocols' protocols\"\r\n Set-ItemProperty IIS:\\Sites\\$parentSite\\$name -name enabledProtocols -value $bindingProtocols\r\n\r\n\t\t$enabledIisAuthenticationOptions = $Authentication -split 's*[,;]s*'\r\n\r\n\tValidate-Parameter $enabledIisAuthenticationOptions -validInput @($anonymousAuthentication, $basicAuthentication, $windowsAuthentication) -parameterName \"IIS Authentication\"\r\n\r\n\t$enableAnonymous = $enabledIisAuthenticationOptions -contains $anonymousAuthentication\r\n\t$enableWindows = $enabledIisAuthenticationOptions -contains $windowsAuthentication\r\n\t$enableBasic = $enabledIisAuthenticationOptions -contains $basicAuthentication\r\n\r\n\ttry {\r\n\r\n\tExecute-WithRetry { \r\n\t\tWrite-Output \"Anonymous authentication enabled: $enableAnonymous\"\r\n\t\tSet-WebConfigurationProperty -filter /system.webServer/security/authentication/anonymousAuthentication -name enabled -value \"$enableAnonymous\" -PSPath IIS:\\ -location $parentSite$virtualPath\r\n\t}\t\r\n\t\r\n\tExecute-WithRetry { \r\n\t\tWrite-Output \"Windows authentication enabled: $enableWindows\"\r\n\t\tSet-WebConfigurationProperty -filter /system.WebServer/security/authentication/windowsAuthentication -name enabled -value \"$enableWindows\" -PSPath IIS:\\ -location $parentSite$virtualPath\r\n\t}\r\n\r\n\tExecute-WithRetry { \r\n\t\tWrite-Output \"Basic authentication enabled: $enableBasic\"\r\n\t\tSet-WebConfigurationProperty -filter /system.webServer/security/authentication/basicAuthentication -name enabled -value \"$enableBasic\" -PSPath IIS:\\ -location $parentSite$virtualPath\r\n\t}\r\n\r\n\t} catch [System.Exception] {\r\n\t\tWrite-Output \"Authentication options could not be set. This can happen when there is a problem with your application's web.config. For example, you might be using a section that requires an extension that is not installed on this web server (such as URL Rewrtiting). It can also happen when you have selected an authentication option and the appropriate IIS module is not installed (for example, for Windows authentication, you need to enable the Windows Authentication module in IIS/Windows first)\"\r\n\t\tthrow\r\n\t}\r\n\r\n Set-WebConfiguration -value \"None\" -filter \"system.webserver/security/access\" -location $parentSite/$virtualPath -PSPath IIS:\\ \r\n if ($requireSSL -ieq \"True\")\r\n {\r\n\t\tWrite-Output \"Require SSL enabled: $requireSSL\"\r\n Set-WebConfiguration -value \"Ssl\" -filter \"system.webserver/security/access\" -location $parentSite/$virtualPath -PSPath IIS:\\ \r\n }\r\n}\r\n",
"Octopus.Action.Script.Syntax": "PowerShell"
},
"SensitiveProperties": {},
Expand Down Expand Up @@ -72,7 +72,7 @@
}
}
],
"LastModifiedBy": "janv8000",
"LastModifiedBy": "joaoasrosa",
"LastModifiedOn": "2015-11-17T08:52:18.577+00:00",
"$Meta": {
"ExportedAt": "2015-11-17T08:52:22.021Z",
Expand Down