I've looked at various examples of setting variables and conditions for tasks in a DevOps pipeline but I can't quite seem to grok it for the usecase I have.
I want a PowerShell task to set a variable to true or false, then use that variable as a condition for another task which will create an artifact.
What I has so far, from reading around online is this:
- task: PowerShell@2
inputs:
targetType: 'inline'
script: |
#Some logic here
if ($logicEvaluatedToTrue) {
Write-Host "Artifacts will be created"
Write-Host "##vso[task.setvariable variable=requiresRelease;isSecret=false;isOutput=true;]$true"
}
else {
Write-Host "No artifacts will be created"
}
failOnStderr: true
- task: PowerShell@2
inputs:
targetType: 'inline'
script: |
#Both of these do not contain any values
Write-Host $env:requiresRelease
Write-Host $requiresRelease
failOnStderr: true
# this just evaluates to Expanded: and(True, eq(Null, 'true'))
- task: PublishPipelineArtifact@1
condition: and(succeeded(), eq(variables.requiresRelease, 'true'))
inputs:
targetPath: 'snip1.zip'
artifact: 'snip1'
publishLocation: 'pipeline'
# this just evaluates to Expanded: and(True, eq(Null, 'true')) too
- task: PublishPipelineArtifact@1
condition: and(succeeded(), eq(variables['requiresRelease'], 'true'))
inputs:
targetPath: 'snip2.txt'
artifact: 'snip2'
publishLocation: 'pipeline'
I've tried setting a variable first like this:
variables:
#existing vars first
requiresRelease: false
But when I do that, the evaluation of the condition becomes Expanded: and(True, eq('false', 'true')) . Any help you have would be appreciated.