Reputation: 14586
I have a task in my pipeline which should be enabled base on the value of a variabe. The variable is defined in a separate yml file and it is set to true or false.
- task: AzurePowerShell@3
displayName: 'Create envionment'
inputs:
azureSubscription: 'id'
ScriptPath: $(workFolder)/Provisions/Environment/create.ps1
errorActionPreference: stop
azurePowerShellVersion: LatestVersion
enabled: $(createEnvironment)
However this gives me an error :
Unexpected value $(createEnvironment)
Is it not possible to achieve this ?
Upvotes: 2
Views: 2899
Reputation: 30313
You can use ${{variables.createEnvironment}}
to refer to the variable. See below:
- task: AzurePowerShell@3
displayName: 'Create envionment'
inputs:
....
enabled: ${{variables.createEnvironment}}
The reason $(createEnvironment)
not working is because $()
is parsed at runtime. But ${{}}
will be parsed at compile time. See here for more information.
You can also use Condition. But you need to wrap the variable createEnvironment
in single quote ''
.See below:
condition: eq(variables['createEnvironment'], true)
Upvotes: 3
Reputation: 221
You should be using condition vs enabled parameter. It should look like this:
- task: AzurePowerShell@3
displayName: 'Create envionment'
inputs:
azureSubscription: 'id'
ScriptPath: $(workFolder)/Provisions/Environment/create.ps1
errorActionPreference: stop
azurePowerShellVersion: LatestVersion
condition: eq(variables[createEnvironment], true)
Upvotes: 1