Jenkins Installation and Configuration with Maven and GitHub

In this tutorial we install Jenkins and configure it to build a Maven project hosted on GitHub.

Note: This post has been updated for Jenkins 2.5x running on Java 21. The original 2014 version deployed Jenkins as a WAR inside Tomcat 7 on Java 7 and walked through a UI that has since changed substantially. Modern Jenkins is self-contained, so you no longer need a separate servlet container, and Git/Maven support now ships with the suggested plugins. The setup below is therefore shorter than it used to be.

Prerequisites

You need three things installed locally before starting:

  • Java 21 (or 25). Current Jenkins LTS releases require Java 21 as a minimum; Java 17 was dropped in the April 2026 LTS line.
  • Maven, to build the project.
  • Git. On Windows, install Git for Windows and select the option that adds the git executables to your PATH, so Jenkins can find them.

Installing Jenkins

Jenkins is distributed as a self-contained web application: a single WAR file you run directly, with no Tomcat or other servlet container required.

  • Download the latest LTS jenkins.war from the Jenkins download page.
  • Open a terminal and run java -jar jenkins.war.
  • Jenkins starts on http://localhost:8080. On first launch it prints an initial admin password to the console (and writes it to <JENKINS_HOME>/secrets/initialAdminPassword). Paste that into the Unlock Jenkins screen.
  • Choose Install suggested plugins. This bundle already includes the Git, GitHub, Maven Integration and Pipeline plugins, so there is nothing extra to install for this tutorial.
  • Create the first admin user, and you land on the dashboard.

In 2014 you had to install the GitHub plugin by hand from the Available plugins tab. Today it comes with the suggested-plugins bundle, so that whole step is gone. If you ever do need it, plugins now live under Manage JenkinsPlugins.

Prefer containers? docker run -p 8080:8080 -p 50000:50000 jenkins/jenkins:lts gives you the same Jenkins instance.

Configuring JDK, Git and Maven

Jenkins can auto-install these tools for you, but pointing it at your existing local installations is faster and more predictable.

  • Go to Manage JenkinsTools.
  • In the JDK section click Add JDK, uncheck Install automatically, then set a Name (e.g. jdk-21) and JAVA_HOME.
  • In the Git section click Add Git, uncheck Install automatically, then set a Name and the Path to Git executable. If git is on your PATH, plain git (or git.exe on Windows) is enough.
  • In the Maven section click Add Maven, uncheck Install automatically, then set a Name (e.g. maven-3) and MAVEN_HOME.
  • Click Save.

These settings used to live under Configure System. In current Jenkins they have their own Tools page.

Building a GitHub project (Freestyle)

Let’s build a real public Maven project: Jenkins’s own sample app, jenkins-docs/simple-java-maven-app, a small “Hello world” with a couple of unit tests.

  • From the dashboard click New Item (this was called New Job in older versions).
  • Enter a name, choose Freestyle project, and click OK.
  • In the Source Code Management section select Git and enter the Repository URL: https://github.com/jenkins-docs/simple-java-maven-app.git. A public repo needs no credentials; for a private one you would add credentials here. Leave Branch Specifier at the repo default (*/master for this project).
  • In the Build Steps section choose Add build stepInvoke top-level Maven targets. Pick the Maven version you configured and enter clean package in Goals.

If the pom.xml is not at the repository root, set its path under Advanced (for example subdir/pom.xml). The sample repo keeps it at the root, so you can skip that here.

  • Click Save, then Build Now.
  • A new build appears in the Build History panel. Open it and select Console Output to watch Jenkins clone the repository, resolve dependencies, run the tests and produce the JAR.

The old Git plugin had a Skip internal tag option to stop it tagging every build. That option is gone; modern Jenkins clones without tagging by default.

Going further: a Pipeline

Freestyle jobs are configured by clicking through the UI. The modern idiom is a Pipeline defined in code: a Jenkinsfile committed alongside your project, so the build definition is versioned with the source. The sample repo already ships one. To use it:

  • New ItemPipeline.
  • Under the Pipeline section choose Pipeline script from SCM, set SCM to Git, use the same repository URL, and set Script Path to Jenkinsfile.
  • Save, then Build Now.

A minimal Jenkinsfile for the same Maven build looks like this:

pipeline {
    agent any
    tools {
        maven 'maven-3'   // the name you set under Manage Jenkins → Tools
        jdk   'jdk-21'
    }
    stages {
        stage('Build') {
            steps {
                sh 'mvn -B clean package'
            }
        }
    }
    post {
        success {
            archiveArtifacts artifacts: 'target/*.jar', fingerprint: true
        }
    }
}

agent any runs the build on any available executor. The tools block pulls in the Maven and JDK installations you configured earlier. The Build stage runs the same clean package goals, and the post block archives the resulting JAR so you can download it from the build page. Because this file lives in the repository, every clone of your project carries its own build definition, which is the real advantage over a click-configured freestyle job. On Windows agents, use bat 'mvn -B clean package' instead of sh.

Conclusion

You installed Jenkins as a standalone application, pointed it at your local JDK, Git and Maven, and built a public GitHub Maven project both as a freestyle job and as a Pipeline. From here you can add a GitHub webhook (under Manage JenkinsSystem) to trigger builds automatically on every push, or extend the Jenkinsfile with test and deploy stages.

References