Git – How to exclude git branch from building in Jenkins

gitJenkins

Here is my current Jenkins setup for a project:

  • one job runs all development branches
  • one job runs all pull requests
  • one job runs only the master branch
  • one job makes the automated release only when master passes

This setup allows me to have continuous automated delivery as well as constant feedback during development. The first 3 jobs also run all tests and coverage reports.

The problem is that I could not find a way to exclude the master branch from the "all development branches" job. It unnecessarily builds master twice every time I merge a pull-request.

Does anybody know how to exclude one branch from the job in Jenkins ?

ps: I am using the Git and the Github plugins. My project is stored on Github.

Best Answer

You can choose "Inverse" strategy for targeting branches to build.

Check out Jenkins job configuration,

  • "Source Code Management" section (choose "Git")
  • Additional Behaviours
  • click "Add" button
  • choose "Strategy for choosing what to build"
  • select "Inverse" strategy in combo box.

(Don't forget to fill in "Branches to build" text field by "master")

See also attachment screenshot image:


enter image description here