babsher
babsher

Reputation: 1016

Hudson/Jenkins Git build all branches

We have a lot of developers creating feature branches that I would like to build. Nightly we run a code quality tool that needs to run on every branch. I also would not like a static configuration because the number of branches changes every few weeks.

Upvotes: 38

Views: 29050

Answers (4)

kert
kert

Reputation: 2271

Old question but somewhat more fitting answer. The multi-branch plugin below allows you to create a build item type that fans out sub-projects with branches, syncing config automatically from top level to sub-projects

https://wiki.jenkins-ci.org/display/JENKINS/Multi-Branch+Project+Plugin

UPDATE 2021 This plugin is marked DEPRECATED

This plugin is deprecated. Please move to the Multibranch Pipeline job type.

For a somewhat more involved approach, Seed plugin gives you a lot of flexibility defining sub-jobs

https://github.com/jenkinsci/seed-plugin/wiki

Upvotes: 2

Delta Echo
Delta Echo

Reputation: 33

The ** for branch specifier will run against all branches AND all tags. If you just want branches, use a branch specifier of refs/heads/*

Upvotes: 2

Squrppi
Squrppi

Reputation: 95

I had the same problem to be solved. Specifically, make a zip file of all branches and offer those as artifacts to be used in different test jobs.

In "Branches to build", put "**"

Then, Execute shell:

while read -ra ITEM; do
  for i in "${ITEM[@]}"; do
    git checkout $i
    <do your stuff>
  done
done <<< $(git branch -r | grep -v "HEAD ->" | xargs -L 1 | cut -d'/' -f2)

This reads the list of branches, checkouts each of them separately and allows to do stuff in each of them. The <<< command converts this output:

  origin/HEAD -> origin/master
  origin/branch1
  origin/master
  origin/secondbranch

into checkout usable list:

branch1
master
secondbranch

Upvotes: 7

Tomasz Bartczak
Tomasz Bartczak

Reputation: 597

In Git configuration there is a field 'Branch Specifier (blank for default): ' if you put there ** it will build all branches from all remotes.

having that you can use an environment variable ${GIT_BRANCH} e.g. to set a title for the build using https://wiki.jenkins-ci.org/display/JENKINS/Build+Name+Setter+Plugin or for other purposes

Upvotes: 42

Related Questions