It looks like variables that do not have values defined aren’t getting passed into the $OctopusParameters collection, does Octopus ignore variables that have blank or empty values?
Hi Shawn,
From my testing just now, it seems to me that the values are included in the $OctopusParameters
collection, but they are being trimmed. i.e. any trailing whitespace is removed.
This behavior was implemented to prevent password copy/paste errors.
Does this fit what your are seeing. Is this behavior causing you a specific problem?
Regards,
Michael
check to make sure variable value is available
if($OctopusParameters -and $OctopusParameters["$($Parameter.Name)"])
{
# set the variable value
$Variable.Value = $OctopusParameters["$($Parameter.Name)"]
}
else
{
# warning
Write-Warning "OctopusParameters collection is null or $($Parameter.Name) not found in collection"
}
The above code hits the ELSE statement for variables that are blank or empty, is this logic incorrect?
EDIT - The $Parameter.Name value directly corresponds to a variable defined in the Variables section. IE, if there is a variable named Variable1.Password, the value of $Parameter.Name is Variable1.Password.
Duplicate post
I believe that’s due to the way PowerShell converts strings to booleans. Empty strings are evaluated as false. If you changed it to:
# check to make sure variable value is available
if($OctopusParameters -and $OctopusParameters.ContainsKey($Parameter.Name) )
{
# set the variable value
$Variable.Value = $OctopusParameters["$($Parameter.Name)"]
}
else
{
# warning
Write-Warning "OctopusParameters collection is null or $($Parameter.Name) not found in collection"
}
I think you will see the behavior you expect?
The ContainsKey method caused all of them to hit the ELSE statement, however, this worked well
if($OctopusParameters -and ($OctopusParameters["$($Parameter.Name)"] -ne $null))
{
# set the variable value
$Variable.Value = $OctopusParameters["$($Parameter.Name)"]
}
else
{
# warning
Write-Warning "OctopusParameters collection is null or $($Parameter.Name) not found in collection"
}
Shawn
I’m glad to hear it’s working for you Shawn. Thanks for the update.
Regards,
Michael
Scratch that, your method is the correct solution. I must have done something wrong the first time I tried it. Thanks for pointing out my logic error
Hah. You’re welcome. Thanks for the update.
Happy Deployments!