0

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? Commented Sep 10, 2019 at 21:47

1 Answer 1

1

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!"
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.