I am building a DevOps pipeline through yaml file which triggers a build for PR. Structure below:
pr:
- dev2
stages:
- stage: PR
condition: and(eq(variables['Build.Reason'], 'PullRequest')
displayName: prBuild
jobs:
- job: DowndSecureFile
if i raise a PR for the first time to the dev2 branch from another branch ex: dev3 it triggers.
Another build fails to trigger in this case:
If the PR is not yet merged:
and I have made additional commit to dev3 then build is skipped for the PR
I understand this is due to this condition where Build.Reason changes to CI:
condition: eq(variables['Build.Reason'], 'PullRequest')
But I am trying to do, that if a pr is still open and if i put additional commits to the PR branch dev3, i need to trigger a build again for that PR. Is there any suitable condition for that? or
Update:
I am using github enterprise, for the repository, no Azure Repos is used here.
should i do something else?
Can anyone help me here? Thanks.
2
Answers
The
Build.Reason
variable have a value ofPullRequest
when the build is triggered by a branch policy as indicated in the docsThis documentation shows how you can setup build validation as a part of your branch policy. The branch policy helps ensure the PR can only be merged if the build is succesful and also require a minimum number of code reviewers.
The manual describes that a new build is triggered for each updated commit to the pull request.
@Roderick Bant has given the doc for
Build.Reason
.On the base of his answer, i want to make additional information.If you want to trigger a build for both PR and CI, you can modify your condition: