Hi,
I’m not sure if this as been fixed in a later version as we’re running on a bit of a back-level version of Octopus Deploy (v2018.10.0, December 2018), but I’m getting an error from Octopus.AzureContext.ps1 after my “Inline Source Code” script has run in a step based on the “Run an Azure PowerShell Script” Step Template.
My script looks like this:
$ErrorActionPreference = "Stop";
Set-StrictMode -Version "Latest";
... some powershell script here that runs without error ...
and the error I get is after my script has run, but in the same step as follows:
The variable '$OctopusDisableAzureCLI' cannot be retrieved because it has not been set.
At D:\Octopus\Work\20190417151113-235310-8095\Octopus.AzureContext.ps1:152 char:10
+ If (!$OctopusDisableAzureCLI -or $OctopusDisableAzureCLI -like [B ...
+ ~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (OctopusDisableAzureCLI:String
) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : VariableIsUndefined
The remote script failed with exit code 1
It looks like my Set-StrictMode is carrying over into the execution context of the internal post-step scripts run by the tentacle and breaking it because it’s referencing variables that haven’t been assigned a value.
I can work around it by just calling Set-StrictMode -Off at the end of my script, but it would be nice if the Octopus.AzureContext.ps1 script worked with strict mode (or ran in a different context).
Cheers,
Mike
P.S. this link gives one way to determine whether a variable has been defined or not before accessing it… https://stackoverflow.com/questions/3159949/in-powershell-how-do-i-test-whether-or-not-a-specific-variable-exists-in-global