Trying to write my first powershell step template (Octopus 2.4.9.166). Some of my params should be mandatory and some should be optional but with sane default values. Have some questions.
- How to specify param default value as null (not an empty string)?
- How to represent a bool default value (not a string value)?
I get this when trying to pass step template variable value of $False to the function in my step template function.
Failed to create new virtual app.
Info 22:33:37
System.Management.Automation.ParameterBindingArgumentTransformationException: Cannot process argument transformation on parameter 'legacyAppPool'. Cannot convert value "System.String" to type "System.Boolean". Boolean parameters accept only Boolean values and numbers, such as $True, $False, 1 or 0. ---> System.Management.Automation.ArgumentTransformationMetadataException: Cannot convert value "System.String" to type "System.Boolean". Boolean parameters accept only Boolean values and numbers, such as $True, $False, 1 or 0. ---> System.Management.Automation.PSInvalidCastException: Cannot convert value "System.String" to type "System.Boolean".
Here is function def and function invocation:
try
{
Write-Host "Step template variable values:"
Write-Host "siteName = $siteName"
Write-Host "appPoolName = $appPoolName"
Write-Host "virtualAppName = $virtualAppName"
Write-Host "enabledProtocols = $enabledProtocols"
Write-Host "idleTimeout = $idleTimeout"
Write-Host "maxProcesses = $maxProcesses"
Write-Host "legacyAppPool = $legacyAppPool"
new-virtualApp -siteName $siteName -appPoolName $appPoolName -legacyAppPool $legacyAppPool -appPoolDotNetVersion $appPoolDotNetVersion -appPoolUser $appPoolUser -appPoolPwd $appPoolPwd -virtualAppName $virtualAppName -enabledProtocols $enabledProtocols -idleTimeout $idleTimeout -maxProcesses $maxProcesses
}
catch [System.Exception]
{
write-host "Failed to create new virtual app."
write-host $error[0].Exception.ToString()
throw
}
function new-virtualApp
{
param(
[parameter(mandatory=$False, HelpMessage='Enter the site name, i.e. Default Web Site')]
[string]$siteName="Default Web Site",
[parameter(mandatory=$True)]
[string]$appPoolName,
[parameter(mandatory=$False)]
[bool]$legacyAppPool = $False,
[parameter(mandatory=$False, HelpMessage='Enter the dot net version for the app pool, i.e. v4.0')]
[string]$appPoolDotNetVersion = "v4.0",
[parameter(mandatory=$True)]
[string]$appPoolUser,
[parameter(mandatory=$True)]
[string]$appPoolPwd,
[parameter(mandatory=$True)]
[string]$virtualAppName,
[parameter(mandatory=$False, HelpMessage='Enter the enabled protocols, i.e. http,net.tcp')]
[string]$enabledProtocols = "http",
[parameter(mandatory=$False, HelpMessage='Enter the number of idle minutes after which the application pool should unload. 0 = no timeout.')]
[ValidateRange(0,60)]
[int]$idleTimeout = 0,
[parameter(mandatory=$False, HelpMessage='Enter the maximum number of worker processes.')]
[ValidateRange(1,16)]
[int]$maxProcesses = 1
)
Can you do any validation in step template form on user input to help guide the user?
Can you have a step template import an custom / existing powershell module previously defined in Octopus rather than defining a new one? If so, how do you bind the declared template params to the powershell function params?
Where can we see when the step template was last updated? Looking for some way to version these guys.
How do we rename an existing step template?
How do we delete an existing step template? i need to delete some test templates / do-overs.