0
votes

I have set a variable in a release pipeline in azure-devops as myFlag : true. I tried to invoke myFlag in a powershell task but am not getting any result. My inline script:

If ( $myFlag -eq 'false' ) {
  Write-Host "Hit!"
} Else {
  Write-Host "Not Hit!"
}

$myFlag is not having any value and hence else block is getting hit.

1
Can you provide the yaml of where it is coming from and how you're then passing it to the powershell task? - David C

1 Answers

1
votes

If ( $myFlag -eq 'false' )

The caused reason of no value in $myFlag is this is a definition format of dynamic variable which just exists in current job. In one world, it is creating a new variable named myFlag rather than getting the value from the variable you pre-defined. That's why no value in $myFlag.

According to your logic of script, you are getting value of myFlag which pre-defined in Variables tab, then compare it with "false". If the value of myFlag is False, print out Hit! in log, otherwise print Not Hit!. So, just change your script as:

If ('$(myFlag)' -eq 'false' ) {
  Write-Host "Hit!"
} Else {
  Write-Host "Not Hit!"
}

Or:

$myFlag = '$(myFlag)'

If ($myFlag -eq 'false') {
  Write-Host "Hit!"
} Else {
  Write-Host "Not Hit!"
}