Carneiro
Carneiro

Reputation: 3509

How to exclude git branch from building in Jenkins

Here is my current Jenkins setup for a project:

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.

Upvotes: 45

Views: 36762

Answers (4)

sashoalm
sashoalm

Reputation: 79685

@Mike's answer would work for most, but note that :^(?!.*master).*$ would match anything that doesn't contain master, i.e. a branch called feature/add-remaster-functionality won't be built as well. A better way would be :^(?!.*^master$).*$ which matches only master, or even :^(?!.*^(master|origin/master)$).*$ which would match master or origin/master.

Upvotes: 7

hi.nitish
hi.nitish

Reputation: 2984

You can use Repository, filter by name(wildcard). Here just provide :^(?!.master).$. skipmaster1

or you can use filter branch using wildcard and exclude master there:skipmaster2 as it successfully scans but later removes from organisation folder scan in case you are using github or bitbucket team project. enter image description here

Upvotes: 2

Rylander
Rylander

Reputation: 20179

You can use :^(?!.*master).*$ as the branch specifier in Jenkins and all branches except master will be built. See answer: https://stackoverflow.com/a/18709097/444639

Upvotes: 20

kyanny
kyanny

Reputation: 1241

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

Upvotes: 66

Related Questions