Monday, March 17, 2014

Save your code from unsafe commits using WSO2 GitHub Pull Request Builder

WSO2 Github Pull Request Builder plugin, a Jenkins plugin, an extended version of the Github Pull Request Builder additionally facilitates merging pull requests automatically if the build went successfully if the user have asked the plugin to merge it while configuring the Jenkins job by giving the relevant config.

Prerequisites


Here, I describe how to install Jenkins on Apache-tomcat.

  1. Download Apache-tomcat.
  2. Download Jenkins as a war file.
  3. Extract tomcat to somewhere(suppose that us $TOMCAT_HOME dir)
  4. Copy the Jenkins.war file to $TOMCAT_HOME/webapps directory
  5. cd to $TOMCAT_HOME/bin and start tomcat by running
    sh catalina.sh start (if you're on linux)
    or
    catalina.bat start (if you're on windows)
  6. Then, browsing the url, http://hostname:8080/jenkins/ will take you to the Jenkins home. Please replace the hostname with the correct hostname or ip-address where the tomcat is running.
  7. The Jenkins home should look like,

  8. Get WSO2 GitHub Pull Request Builder and Updated Github Api Plugin(follow the "Build from the Source" section below).

Installing WSO2 Github Pull Request Builder on Jenkins

  1. Go to Jenkins Plugin Manager in Manage Jenkins->Manage Plugins
  2. Go to Available tab.


  3. Find the Github-Plugin and install it. You can filter the plugins using the Filter at the upper right corner.
    If you cannot find the plugin, please go to Advanced tab and try Check now at the bottom right corner and try again this step.
  4. Go to Advanced tab and upload WSO2 GitHub Pull Request Builder and Updated Github Api Plugin.
  5. Now let WSO2 GitHub Pull Request Builder get installed and restart Jenkins, that will cause Updated Github Api Plugin to replace the previously installed plugin.
  6. Now, the installation is fine.

Global Configuration

  1. Go to Jenkins Configuration in Manage Jenkins->Configure System
  2. Scroll down to the GitHub pull requests builder section.

  3. Click Advanced button and provide github Username and the Password.
  4. Scroll up to check the JDK and Maven sections too to know if the java and maven are configured. if not, please configure them too.

Job Level Configuration


  1. Go to the job page shown in Jenkins home that you need to configure the plugin. If you don't have created jobs, yet, create one by clicking on the "New Item" and provide a name and tick on the Build a maven2/3 project and click ok. Now the job should be appeared on the home as described above. Now go to the job page by clicking on the job name.

  2. Go to Configure page. Configuration should be as follows,

    1. Github project - The Github Project url
    2. This build is parameterized - Should be Checked, and add a string parameter giving some name(here we use sha1)

    3. Git Should be selected in the Source Code Management section.

      1. Repository URL - Provide the URL of the Github repo
      2. Credentials - Add credentials and select it.
      3. Refspec in Advanced - "+refs/pull/*:refs/remotes/origin/pr/*" (without double quotes, copy and paste the value)
      4. Branch Specifier (blank for 'any') - provide the build parameter name here wrapping with curly braces and a leading dollar sign(here it is ${sha1} since we used the name as sha1 before)

    4. Check GitHub pull requests builder in the Build Triggers section

      1. Admin list - Configure admin usernames in the test area
      2. Check Merge pull request automatically and Build every pull request automatically without asking (Dangerous!) in Advanced
      3. Crontab line in Advanced - "*/1 * * * *" (copy and paste the value without quotes, this value is to trigger the build in every minute, change the number to configure the number of minutes)

  3. Now save the config.

Now, You could easily test the plugin by sending a pull request to the github repo.

Build the plugin from the Source


Check out the source code. Build the code like a normal maven project in the following order.
  1. github-api
  2. github-api-plugin
  3. ghprb-plugin
Go to the targets of the 2nd and 3rd build and find .hpi files.


No comments:

Post a Comment