It's about open source softwares

Showing posts with label jenkins. Show all posts
Showing posts with label jenkins. Show all posts

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:

Thursday, July 2, 2015

Backup and Restore JENKINS Jobs


In an organization Jenkins plays important role achieving continuous integration and deployment/delivery a.k.a CI/CD pipeline. There are other tools present for achieving CI/CD like Travis, Jetbrains, Bamboo, etc. I am using Jenkins because it is popular in open source community.

While automating the tasks we are making changes in Jenkins jobs. Over the period of time Jenkins server is filled with lot of jobs. In case failure of Jenkins server, migrating Jenkins server to another machine or accidentally deletion jobs cause lot of trouble for DevOps. It is necessary to have backup of Jenkins jobs, so that we can restore them in short period of time. There are several plugins present for Jenkins like backup-plugin, configuration-history-plugin which does job for you. For this you have to do additional configurations. 

Jenkins provides REST API for managing jobs easily. Jenkins stores the job configuration in config.xml file that is present in the root directory of job. If you are OK with creating/migrating jobs without build number, build history, etc. then we can create/migrate jobs very easily with the help of jenkins's job REST API.

Backup Jenkins Job


Taking backup of Jenkins job is quite easy, you just have to login to your Jenkins server through browser. After login append "/job/job-name/config.xml" to URL. It will show job configuration. Just save the config.xml file contents.  

Here, I am backing up automerge-test job.


Jenkins Job Backup
 If you are familiar with CURL then using GET method you can get config.xml file.

Restore Jenkins Job


Restoring of jenkins jobs are as simple as taking backup. 
  • Create an empty job in Jenkins
  • POST the config.xml to Jenkins server using POSTMAN 

First you have to create an empty Jenkins job on the same server or new server in case of migrating jobs in to another server.

Create empty jenkins job

Newly created automerge-test job doesn't have anything right now.

Empty Configuration

Now install POSTMAN extension to your browser. Using POST method provide a job configuration to jenkins server. Use http://<jenkins_server_name>/job/<job_name>/config.xml in URL and paste config.xml content in body section with raw-text formatting.

Press Send button to post the config.xml contents to Jenkins server.

Restore Job using POSTMAN


 Using POST API configurations filled in newly created job. Confirm Job configuration in Jenkins.

Job Configuration

Jenkins jobs are backup and restore successfully using REST API.

Share: