It's about open source softwares

Wednesday, August 5, 2015

Merge GIT Branches Using JENKINS

Continuous Integration and deployment or delivery (CI/CD) pipeline consists of many machines or environments. It has development, production, integration, testing and staging machines. Each machine has separate branch in GIT to store the source code.

In GIT, Development branch has all code from developers which are in development phase. After completing development, a developer pushes his/her code to integration branch. It results into running build scripts, testing scripts to check the integrity of code. Likewise code pushed from integration branch to staging and later production branch.

At each stage of CI/CD pipeline, one has to push code from one branch to another or merge them. As DevOps guy one should not do it manually. Jenkins provides the facility to merge two git branches and push it to remote branch as part of build tasks.

Merging git branch using Jenkins task consists of following steps,

  • Install GIT plugin in Jenkins
  • Create Jenkins task for branch merging
  • Configure Jenkins task


Install GIT plugin

Installing plugins to Jenkins is easy. For installing GIT plugin in your Jenkins instance, refer to the link below.

Create Jenkins task


Create new Jenkins task which will merge the two GIT branches.



Configure Jenkins task


I have created an automergejenkins Github project. It has four branches master, develop, integration and production.

At this post, I am demonstrating how to configure Jenkins task to merge develop branch to integration.   
  • Source code configuration
In source code management section, specify the GIT repository and branch to build. I am building develop branch and merging it to integration branch.

Press Add button to add "Additional Behaviours". It shows different build options. 
Select "Merge before build" option and specify branch to which develop branch is going to merge.
   

If you need to specify any build command after merging of branches you can do it in Build section.
  • Post Build Action
After configuring the build option, we have to publish merge result to remote branch. 
In "Post-build Action" section add Git Publisher option which will push the merge results only if build succeed.



When you build this task, develop branch got merge into integration branch. You can build the task manually or configure it to build on the other build task results.


References,

  • http://blog.cloudbees.com/2012/03/using-git-with-jenkins.html
  • http://www.vogella.com/tutorials/Jenkins/article.html
  • https://wiki.jenkins-ci.org/display/JENKINS/Git+Plugin

Share:

0 comments:

Post a Comment