简体   繁体   中英

Jenkins and Github trigger PUSH from specific branch

I set up the Github webhook in Jenkins and I created a job with the following configuration:

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

However, every time I push something from any branch, the job build a new version (using the branch which I specified).

I set up the job by reading some related questions on Stackoverflow but all those questions are quite old and without a clear solution:

GitHub WebHooks triggered globally instead of per branch

Trigger Jenkins job on GitHub PUSH to specific branch

Is it possible to trigger Push only from a specific branch?

You are using a GitHub Webhook to trigger a preconfigured job. Your Job has the Branch "JENKINS-TEST-AUTODEPLOYMENT" hardcoded, so it will always build this branch only, no matter which branch you are pushing on GitHub.

How about using GitHub Branch Source Plugin ? With this Plugin, Hooks will be auto-created in github for the corresponding repos. Each Branch will have a job in jenkins, which is also auto-created as long as you have a Jenkinsfile inside your Repo. With this your desired state should be easily achievable.

Finally I did it by using Multibranch Pipeline .

  • In Branch Sources:

    1. Add credentials and repository URL.
    2. In Behaviours add: Discover branches: all branches.
    3. Filter by name (with regular expression): for example, ^master|dev|release. $*
  • In Build Configuration add the path to the Jenkinsfile.

So the job will scan for all the branches of the repository that match with the regular expression.

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