Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 885
babsher Avatar asked Mar 11 '13 17:03

babsher


People also ask

How do I build multiple branches in Jenkins?

When you are interested in using a job to build multiple branches, you can choose how Jenkins chooses the branches to build and the order they should be built. This extension point in Jenkins is used by many other plugins to control the job as it builds specific commits.

How does Jenkins merge work with Git?

In this scenario, on every change of integration, Jenkins will perform a merge with the master branch, and try to perform a build if the merge is successful. It then may push the merge back to the remote repository if the Git Push post-build action is selected.

Why do we need Git pipeline in Jenkins?

Was needed when using Git within the Multi SCM plugin. Pipeline is the robust and feature-rich way to checkout from multiple repositories in a single job. An experiment was created many years ago that attempted to create combinations of submodules within the Jenkins job.

What is the build strategy in Jenkins?

This extension point in Jenkins is used by many other plugins to control the job as it builds specific commits. When you activate those plugins, you may see them installing a custom build strategy. The maximum age of a commit (in days) for it to be built.


2 Answers

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

like image 180
Tomasz Bartczak Avatar answered Sep 28 '22 03:09

Tomasz Bartczak


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 
like image 26
Squrppi Avatar answered Sep 28 '22 03:09

Squrppi