简体   繁体   中英

Azure Devops pipelines to trigger ONLY on Merge

I'm looking on a way to trigger a Azure pipeline ONLY on successful (or attempted) pull request merge.

Now I have:

trigger:
 branches:
  include:
    - DEV

steps:
- script: FOO

But this runs EVERY time there is a change on the DEV branch and I would like to avoid that.

Besides, I want a programmatic response not going trough the UI each time.

I'm looking on a way to trigger a Azure pipeline ONLY on successful (or attempted) pull request merge.

There is no such out of box way to achieve this at this moment.

We could only set the CI trigger on the target branch, but we could set the condotion for the pipeline to avoid build any task:

and(succeeded(), eq(variables['Build.Reason'], 'PullRequest'))

If there is a change on the DEV branch and it would be avoided by the condition.

Note: With above way, the pipeline will be triggered, but no task will be executed.

And if you even do not want the pipeline be triggered. You could add new pipeline with powershall task to invoke REST API to trigger above pipeline and set the condition to the powershell task.

In this way, the pipeline will only triggered when the commit comes from the PR.

The trigger you have set is a CI trigger, it will work whenever the target branch has a new commit.

Currently, there isn't a trigger that works when a pull request is completed.

The feature closest to your needs is PR triggers and build validation branch policy . They will work when a pull request is created or when it has been changed .

If you are using Azure Repos Git , please use branch policy for build validation . If you are using GitHub or Bitbucket Could , please use pr triggers . Click the documents for the detailed information.

Besides, you can use branch policy to prevent the direct commits. When you set the branch policy of any type, only users with "Bypass policies" permission can commit to the branch directly. The rest of the users must commit the branch through a pull request.

How to create branch policy: Branch policies and settings .

How to set "Bypass policies" permission: Set Git repository permissions .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM