Search This Blog

Monday, June 2, 2014

Auto Merging of Git Branches through Jenkins

Two Git branches can be merged and pushed to remote as a part of the build process. This is possible with Jenkins Git plugin with just 2-3 steps configuration. Lets see that in detail.

  • Create/configure a job in Jenkins
  • In Source code management configure the git repository and the integration branch.
    • While merging Test4 branch into Test3 branch; integration branch is Test4 and the Branch to merge to is Test3
  • Click on Advanced button of the branches. It shows more option to configure your merge options
  • Select the option merge before build. The purpose of selecting this option is if the merge results into conflicts, the build will fail; Then we need to manually fix the conflicts and then start the job. This is a pre-build step.
  • Configure the branch in which integration branch has to be merged.
  • Add your build steps as required. Remember that the work space is now containing the merge result. 
  • If this merge results need to be pushed to remote, configure a post build action 'Git Publisher'
  • Select option 'Merge Results'. This tries to push the head version of the target to the last commit of integration branch.
  • Select option 'Push Only If Build Succeeds' if it is required to push the merge result only if the build is  success; Else remote copy will not be updated. 
  • If required, the branch can be tagged as per the below image.
Finally if you check your remote repository 'Test3' Branch, you can find that Test4 has been merged into it.

1 comment:

  1. Is credentials required? I am getting Access denied message for git publisher

    ReplyDelete