Jenkins installation and configuration with Maven, Ant and GitHub

In this tutorial we are going to describe Jenkins installation and configuration with Maven, Ant and GitHub. We are going to use a Tomcat Application Server 7. If you don’t have Tomcat installed please refer to our earlier tutorial Eclipse Tomcat 7 Setup where you will find simple steps to accomplish Tomcat installation. You will need a Java 6+ SDK installed as well.
This tutorial is divided into sections:
- Git binaries installation
- Jenkins installation
- Jenkins GitHub plugin installation
- Jenkins Maven, Ant and Git configuration
- Testing – Building public repository hosted on GitHub

Git binaries installation

At first we need client tool using which git operations like cloning, fetching, pooling can be done. We have chosen git client implementation available at git-scm.com. Download and install it.
Important thing is to select Run Git from the Windows Command Prompt option on Adjusting your PATH environment installation screen so that git client executables are added to your PATH variable.

Jenkins installation

Now we are going to install Jenkins. Jenkins is a web application that is being distributed as a WAR archive. Follow this few steps:

Jenkins GitHub plugin installation

In order to build projects that are hosted on a GitHub repository our Jenkins installation has to have GitHub Plugin installed. Follow this steps:

  • Navigate to http://localhost:8080/jenkins
  • Click Manage Jenkins
  • Click Manage Plugins
  • Click the Available tab
  • In the Filter text field enter ‘github’
  • Select GitHub Plugin and click Download now and install after restart button. Appropriate plugins are being installed
  • After installation finishes restart Tomcat

Jenkins Maven, Ant and Git configuration

Now we are going to configure Jenkins to use Maven, Ant and a Git client local installations. The steps are:

  • Navigate to http://localhost:8080/jenkins
  • Click Manage Jenkins
  • Click Configure System
  • In the JDK section click Add JDK button, uncheck Install automatically checkbox and enter Name and JAVA_HOME values
  • Int the Git section click Git Installations... button and enter Name and Path to Git executable values

since we have pointed that git client binaries needs to be added to the PATH variable during Git client installation, just enter git client program name – git.exe

  • In the Ant section click Add Ant button, uncheck Install automatically checkbox and enter Name and ANT_HOME
  • In the Maven section click Add Maven button, uncheck Install automatically checkbox and enter Name and MAVEN_HOME
  • Click Apply and then Save

Testing – Building public repository hosted on GitHub

Now let’s test our configuration. We are going to build one of our project hosted on GitHub. This projects uses maven. It can be found at https://github.com/itcuties/Axis-2-client. Here are the steps:

  • Navigate to http://localhost:8080/jenkins
  • Click Click New Job
  • Select Build a free-style software project option, enter Job name value and click OK
  • In the Source Code Management section select Git option
  • Enter Repository URL – for this test let’s use https://github.com/itcuties/Axis-2-client.git
  • Click Advanced button
  • Click Advanced button – this is the other button that displays after the first click :)
  • Check Skip internal tag checkbox

This will tell Jenkins to clone the repository. If not checked Jenkins would create a separate tag for each build in the repository.

  • In the Build section select Invoke top-level Maven targets
  • Enter compile in the Goals field
  • Click Advanced... button
  • Enter HighScoresServiceClient\pom.xml in the POM field

You need to tell Jenkins where to find pom.xml file when looking from the root of the project.

  • Click Apply and then Save
  • On the next screen click Build Now button
  • In the Build History section a new build has appeared
  • Move your mouse over it and select Console Output item – you can see how project is being cloned and build.

Our Jenkins installation and configuration with Maven, Ant and GitHub works.

3 Responses to "Jenkins installation and configuration with Maven, Ant and GitHub"

  1. arun says:

    Hi need a help from u girls … i did all those steps but jankins cant fetch the datas from git

    Reply
  2. satish says:

    Hi, i did all steps, got this error.
    Started by user anonymous
    Building in workspace C:\Users\satishp\.jenkins\workspace\buildtest
    Cloning the remote Git repository
    Cloning repository https://github.com/itcuties/Axis-2-client.git
    Fetching upstream changes from https://github.com/itcuties/Axis-2-client.git
    ERROR: Error cloning remote repo ‘origin’
    hudson.plugins.git.GitException: Command “git fetch –tags –progress https://github.com/itcuties/Axis-2-client.git +refs/heads/*:refs/remotes/origin/*” returned status code 128:
    stdout:
    stderr: error: Connection time-out while accessing https://github.com/itcuties/Axis-2-client.git/info/refs?service=git-upload-pack
    fatal: HTTP request failed

    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1276)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1146)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$200(CliGitAPIImpl.java:87)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:254)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$2.execute(CliGitAPIImpl.java:410)
    at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:847)
    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:880)
    at hudson.model.AbstractProject.checkout(AbstractProject.java:1320)
    at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:609)
    at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:88)
    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:518)
    at hudson.model.Run.execute(Run.java:1688)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
    at hudson.model.ResourceController.execute(ResourceController.java:88)
    at hudson.model.Executor.run(Executor.java:231)
    ERROR: null
    Finished: FAILURE

    Reply

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Java by Example App is available at Google Play Store NOW