Is it possible to trigger Jenkins from one specific branch only?

Viewed 14770

My situation is the following: I have three branches in a repo: master, dev and staging. And I have one job for each one of these branches, configured in 'Branches to build' section in Jenkins. origin/master, origin/dev, origin/staging.

Bitbucket triggers the job to build whenever there are changes to the repository via a repository hook .(https://confluence.atlassian.com/display/BITBUCKET/Jenkins+hook+management).

However, when I push to master, all jobs starts to build, and the same with the other two ones.

I want Jenkins "master" job to be built only when I push to master branch. Jenkins "dev" job to dev branch. Jenkins "staging" job to dev staging.

Is there a way to control this behaviour?

4 Answers

Yes!! You can trigger the jenkins build whenever there is a commit or merge into a specific branch of the git repo.

STEPS:

  1. Configure the webhook for your jenkins instance in the Webhook section of the github Repository, the Payload URl will look similar to,

    http://jenkinsinstance:8080/github-webhook/

  2. In the Jenkins Job configuration just enable, GitHub hook trigger for GITScm polling

  3. Then in the SCM section add the below configuration available in the image, assuming the branch you want to build being the Hotfix branch. The Below image defines the exact configuration of SCM section.

SCM Configuartion image

  1. Once done, try to commit code changes to the Hotfix branch, which in return should trigger the jenkins job.
Related