4

Need to trigger CI build job when a PR is merged to master (only when change is inside ./rel/* path) but not have CI build triggered when the Pull Request (PR) is created. So I have the trigger config as below.

trigger:
    branches:
        include:
        - master
    paths:
        include:
        - ./rel/*

pr: none # will disable PR builds (but not CI builds)

But it fails to trigger CI build when pr: none is added. If pr: none is removed, The Job is getting triggered for both PR and a merge to master. I would only need the job/CI build to run on a merge to master.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Michael George
  • 647
  • 9
  • 15

2 Answers2

2

The paths filter in the YAML is looking at paths in your repository file structure, not the branch path. To have it only trigger on rel branch, replace the master under the include branches with ./rel/* (or the correct value).

We have a more defined pipeline that runs unit tests on PR and then only packages for release on merge into the master branch. We do this by having our trigger set to the master branch and using conditions for each stage in the multi-stage pipeline. Check those out as well.

krb224
  • 345
  • 1
  • 11
  • Need to trigger CI build job when a PR is merged to master branch (only when change is inside ./rel/* path). – Michael George Nov 27 '19 at 20:29
  • Ok. I understand your path now. To accomplish this, I would use a condition on your first job similar to `ne(variables['Build.Reason'], 'PullRequest')`. This will skip that job for PRs but execute it for master; however, the trigger will fire on both PRs and merges. It just will not execute anything on PRs. – krb224 Nov 27 '19 at 20:35
  • Will give Conditions a go. Thanks. But I am still wondering why pr: none is stopping CI Trigger. – Michael George Nov 27 '19 at 20:37
  • Krb, I could achieve the intended flow by using Jobs & conditions as suggested by you, Thanks . But would still be looking forward to know the actual issue with pr: none problem. – Michael George Nov 27 '19 at 22:07
  • @MichaelGeorge did you get this resolved like you wanted? We need the same functionality, where CI runs normally in pushes, but not when done through PR. – John C May 21 '20 at 11:46
  • 1
    Yes. Looks like Azure has fixed the problem. So if you set pr:none. IT would not get triggered for PR. – Michael George Feb 06 '21 at 13:46
2

Solved! This works now.

trigger:
    branches:
        include:
        - master
    paths:
        include:
        - ./rel/*

pr: none # will disable PR builds (but not CI builds)

Also you can configure / override using the classic azure devops UI from Triggers.

Ref : https://learn.microsoft.com/en-us/azure/devops/pipelines/repos/azure-repos-git?view=azure-devops&tabs=classic#ci-triggers

PR trigger

CI trigger

Michael George
  • 647
  • 9
  • 15