[Tutorial] Jenkins CI with Maven/Github Integration

Discussion in 'Resources' started by sgtcaze, Apr 23, 2014.

Thread Status:
Not open for further replies.
  1. Offline


    Hey everyone, my name is sgtcaze, and today I am going to show you how to make your own Continuous Integration (Jenkins) server! These are very useful to build and host projects, as well as providing early access to development builds (while being Bukkit policy compliant).

    This tutorial will cover running Jenkins on CentOS 6 64 Bit. You will need a VPS or dedicated machine.

    Prerequisites (for this tutorial):
    1) "Wget" installed (yum install wget)
    2) "Apache" installed (yum install httpd)
    3) Java 7 JDK installed (yum install java7)

    Installing Jenkins & Configuration:
    Step 1: Downloading and installing Jenkins
    First let's use “Wget” to download the Jenkins repository. Run these three commands (they will download/import/install):
    sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo
    sudo rpm --import http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key
    sudo yum install jenkins
    Step 2: Start Jenkins (MUST have Java installed before hand)
    sudo service jenkins start
    Step 3: Create Administrator & Setup Security
    Click "Manage Jenkins" on the left side. Now click on "Configure Global Security". Under "Security Realm", select "Jenkins' own user database", and "Allow users to sign up".

    Under authorization, select "Matrix based security". Here, you will define your administrator username (very important). I am going to make mine "admin", and give it EVERY permission. Click "Apply" and then "Save".

    Navigate to YourIP.com:8080/signup and register with the username you chose. (Full name will be displayed, if you don't want this, have that be the same as your username).

    Optional: Its probably best to go back to Manage Jenkins > Configure Security and un-check "Allow users to sign up". This keeps your Jenkins from unwanted usernames/people.

    Step 4: Setting up Github Integration
    Now its time to install the GitHub plugin. Go to Manage Jenkins > Manage Plugins > Available and search for "Github Plugin". Download and setup the installation.

    While this installs, let's quickly install Git on our machine. This is necessary for Jenkins to find git properly.
    yum install git
    Step 5: Setup Java JDK, Git and Maven
    Let's go back to Manage Jenkins > Configure System

    Open the JDK tab, and name the JDK: LocalSDK. Select install automatically. Choose Java SE Development Kit 7u55, agree to the terms.

    Under "Git", make sure the name is Default, and the Path to Git executable is "git"

    Under Maven, the name should be Maven 3 with "install automatically" from Apache 3.2.1

    Setup Jenkins Projects:
    On the homepage, let's select "New Item", call it "Test". Select "Build a free style software project". Here you can enter the Project Name and Description. Now for the standard setup:

    1) Ensure "JDK" is set to LocalSDK (if you see this option)
    2) Under source code management, select "Git"
    3) Enter your repository url (example: https://github.com/sgtcaze/LilyPadCompass.git)
    4) Under build triggers, to build once changes are made on GitHub, select the Trigger Builds Remotely, and spam an authentication token (it can be anything at all)
    5) Under "build" select Maven version: Maven 3, with the goal of "clean install"
    6) Finally, under "Post-build Actions" enter: target/*.jar (this will save all Jars created)

    Automatically Build Github Projects:
    To make Jenkins auto build projects from Github, you're going to want to do the following:

    1) Navigate to your project and select "Settings"
    2) Select "WebHooks & Services" and click on "Add webhook"
    3) Enter in the url of your Jenkins, as well as the token you spammed earlier

    Since Maven 3.2.1 will be installed by Jenkins, your project will take a while to build the first time through.

    Sources of Error:
    1) If you cannot access YourIP.com:8080, and Jenkins and Apache are running, it's likely an IP tables issue
    2) If you get "unable to locate javac compiler", you are attempting to build the project using a JRE instead of a JDK

    Questions or concerns? Improvements? Comment below :3
  2. Offline


    I had to find the github plugin and install it before I could do this step
  3. Offline


    Very nice :)
Thread Status:
Not open for further replies.

Share This Page