Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set condition for pull request and non-pullrequest stage in azure devop pipeline?

I am learning to use azure devop's yaml pipeline.

On one stage, I put this condition in

condition: and(succeeded(), eq(variables['System.PullRequest.PullRequestId'], 'Null')
variables:
  prId: $(System.PullRequest.PullRequestId)
  reason: $(Build.Reason)

Basically only run this stage when it is not a pull request. However, when I triggered the pipeline manually, azure devop decides to skip this. So I added build reason and pullrequestId as variables then output it.

write-host "------------------------------"
write-host '$(reason)'
write-host "------------------------------"
write-host '$(prId)' 

The output are:

Manual

$(System.PullRequest.PullRequestId)

I was thinking when it is not triggered by a PullRequest, the $(System.PullRequest.PullRequestId) should be either null or a empty string. Looks like it is not the case. The document say PullRequestId will only be populated when it is a pull request, but I don't really know what the value is when it is not populated. Seems not Null at least.

So is buildreason the reliable condition to differ between a PR or non-PR run other than PullRequestId?

like image 426
daxu Avatar asked Dec 30 '25 08:12

daxu


1 Answers

So is buildreason the reliable condition to differ between a PR or non-PR run other than PullRequestId?

Yes. You can use the following script:

condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest'))

The document say PullRequestId will only be populated when it is a pull request, but I don't really know what the value is when it is not populated.

The variable is not exist when it is not populated. So in your case, the value of variables['System.PullRequest.PullRequestId'] is 'System.PullRequest.PullRequestId'.

like image 104
Jane Ma-MSFT Avatar answered Jan 01 '26 03:01

Jane Ma-MSFT



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!