Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deal with Null for custom condition in Azure Pipeline?

Tags:

azure-devops

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.

like image 209
sandayuu Avatar asked Jul 03 '19 17:07

sandayuu


Video Answer


1 Answers

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:

enter image description here

enter image description here

In the log, we could see that task is executed:

enter image description here

Hope this helps.

like image 180
Leo Liu-MSFT Avatar answered Sep 26 '22 17:09

Leo Liu-MSFT