Reputation: 1995
Im learning YAML and want a stage to run only when a PULL Request has been made on a particular branch. How can i do this?
Upvotes: 2
Views: 4058
Reputation: 35494
To run a stage only when a pull request has been made on a particular branch, you can set the condition in the stage.
condition: and(eq(variables['System.PullRequest.TargetBranch'], 'refs/heads/branchname'), eq(variables['Build.Reason'], 'PullRequest'))
Here is an example:
stages:
- stage: A
condition: and(eq(variables['System.PullRequest.TargetBranch'], 'refs/heads/branchname'), eq(variables['Build.Reason'], 'PullRequest'))
jobs:
- job: A1
steps:
- script: xx
You can use predefined variables: System.PullRequest.TargetBranch
and Build.Reason
to filter the trigger method and pull request target branch.
For more detailed info, you can refer to the docs: Condition and Predefined variables.
Upvotes: 6