I'm finding the best way to find a variable is null on the custom condition.
I tried to compare null. However, Azure Pipeline complains cause error, if I configure like this.
and(failed(), ne(variables['Some'], Null))
Also, This configuration doesn't throw an error, however, when the 'Some' is null, the condition becomes false. Since Null and 'Null' is different.
and(failed(), ne(variables['Some'], 'Null'))
I eventually come up with a workaround. However, it is not cool way. I add PowerShell task, and create this script.
if ($env:Some -eq $null) {
Write-Host "##vso[task.setvariable variable=SkipSome]True"
}
then configure custom condition
and(failed(), ne(variables['SkipSome'], 'True'))
I expect there is a way to compare with null without the powershell. However, I can't find it on the official documentation.
How to deal with Null for custom condition in Azure Pipeline?
To deal with Null for custom condition, we should use ''
instead of Null
or 'Null'
.
You can check the String for some details.
So, you can configure it like following:
and(failed(), ne(variables['Some'], ''))
To test it more intuitively, I change the ne
to eq
:
and(failed(), eq(variables['Some'], ''))
Then I set the variable is empty on the Variable tab, and add a Inline powershell task with above condition:
In the log, we could see that task is executed:
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With