简体   繁体   中英

How to trigger a Jenkins pipeline only when a pull request is made from a specific branch in GitHub?

Our team changed the branching strategy and that requires me to change the Jenkins settings. There is a main "master" branch and a "dev" branch.

The devs will make their individual discrete pull requests (PRs) to the dev which will trigger some unit tests on GitHub Actions, but when a PR is made from the "dev" branch to the main "master" branch a Jenkins pipeline should be triggered.

As I have currently configured the process, the Jenkins pipeline is triggered on every single pull request, regardless of the branch but what I am trying to do is only trigger the Jenkins pipeline every time a PR is made specifically the from "dev" branch to the "master" branch.

In this situation, you can use several strategies.

First: you may want to have a naming convention in place for the branches that are opened against dev branch and plan to be eventually merged there. You can then set up the pipeline to filter based on the match between a branch name and the naming convention. Note that this will trigger a job on a branch, as opposed to on PR.

Second: you may want to fire a pipeline anyway on every PR, find out the destination branch, and if it does not fit your configuration, bail out early and abort the build.

In a somewhat similar situation, we use the second approach.

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