I'm working on a Jenkins job and i need it to build two branches in the same repository. How can i do this?
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.
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.
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.
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).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With