Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins and multiple git branches?

I'm working on a Jenkins job and i need it to build two branches in the same repository. How can i do this?

like image 724
Marx Avatar asked Sep 02 '11 19:09

Marx


People also ask

Why do we need multi branch pipeline in Jenkins?

The Multibranch Pipeline project type enables you to implement different Jenkinsfiles for different branches of the same project. In a Multibranch Pipeline project, Jenkins automatically discovers, manages and executes Pipelines for branches which contain a Jenkinsfile in source control.

Can a Jenkinsfile have multiple pipelines?

Creating Multi-branch Pipelines. The Multibranch Pipeline project type enables you to configure different jobs for different branches of the same project. In a multi-branch pipeline configuration, Jenkins automatically discovers, manages, and executes jobs for multiple source repositories and branches.

What is branching strategy in Jenkins?

Simply put, a branching strategy is something a software development team uses when interacting with a version control system for writing and managing code. As the name suggests, the branching strategy focuses on how branches are used in the development process.


2 Answers

Considering that Jenkins cannot execute one job on two versions of a repository (which is what would be getting the content of two different branches), I would suggest making two different jobs, one for each branch (with the Jenkins Git plugin).

like image 81
VonC Avatar answered Oct 14 '22 08:10

VonC


Are you asking if you want to build two branches in the same checked-out workspace directory?

If in the same workspace directory, all you need to do is create a script that will checkout one branch, build it, and when done, checkout the next branch and then build it.

This single script will then be the one to be called by the single Jenkins job.

For example, your build script would look something like this:

git clone url:repo.git workspace
cd workspace 
git checkout branchA
make
# now you're done building branchA
# next checkout branchB and run make
git checkout branchB
make
# now you are done building branchB

Each checkout will install the files for the branch desired. And this will build it accordingly. However, since they will be sharing the same workspace directory, this could mean that new files would be produced by the first build which will then be present when the second build runs. I assume this is the effect that you want because you wanted to build two branches in the same workspace directory.

Update: Use git clean -xdf if you want to have a fresh workspace for the next build.

like image 29
alvinabad Avatar answered Oct 14 '22 08:10

alvinabad