I have a powershell script, which is not in a job, task, or stage, it's on its own. running in my DevOps build yaml like this:
- powershell: |
if (//something that's irrelevant) {
Write-Host "##vso[task.setvariable variable=myCustomVar;isOutput=true]true"
} else {
Write-Host "##vso[task.setvariable variable=myCustomVar;isOutput=true]false"
}
After this powershell script, I have another script to echo out myCustomVar to see what the value is. Like this:
- script: |
echo "What is my custom variable?"
echo $(myCustomVar)
When the build runs, in the devops logs, it echos literally "$(myCustomVar)" and not either True/False
After that, I have a task which sends an email, but we only want to send an email if myCustomVar
is true. So I use a conditional.
- task: SendEmail@1
displayName: "Send email"
condition: and(succeeded(), eq(variables.myCustomVar, true))
however, this is breaking. I've tried a few other ways of doing it. myCustomVar
, on the task condition, always returns NULL. Any help on syntax?
Set-Variable
only affects the local scope of the running PowerShell task - you need to output a special macro string to set a pipeline variable from inside the script ā Mathias R. Jessen