Dev Genius

Coding, Tutorials, News, UX, UI and much more related to development

Follow publication

Jenkins + Git

Integrate Jenkins with GitHub for a simple Java application

Chamali Vishmani
Dev Genius
Published in
4 min readMar 12, 2025

--

Jenkins is a powerful automation tool used for continuous integration and deployment. To set up Jenkins for building a Java project from a GitHub repository, you need to configure JDK, Git, and create a Jenkins job. This guide will walk you through the process step by step.

1. Installing and Configuring JDK and Git in Jenkins

Before running Java-based builds, you need to ensure Jenkins is properly configured with JDK and Git.

Configuring JDK in Jenkins

  1. Open Jenkins Dashboard and navigate to Manage Jenkins > Tools.
  2. Under JDK installations, specify the path to your JDK directory.
JDK Installations

Configuring Git in Jenkins

  1. In the same Manage Jenkins > Tools section, locate the Git installations.
  2. Provide the path to the Git executable installed on your system.
  3. Click Apply and Save.
Git Installations

2. Creating a Jenkins Job

Creating a New Jenkins Job

  1. Open Jenkins Dashboard and click New Item.
  2. Enter a name for your job.
  3. Select Freestyle project and click OK.
New Item in Jenkins

4. You will be redirected to the configuration page where you can add a description for the job.

3. Connecting a GitHub Repository

Adding a Git Repository

  1. Scroll down to the Source Code Management section.
  2. Select Git and enter the GitHub repository URL.

Link to my repository

How to get the GitHub repository URL
Source code management — Git

Setting Up Credentials for GitHub

To access private repositories, you need to authenticate using a Personal Access Token:

  1. Generate a Personal Access Token from GitHub with the necessary scopes.
Getting a personal access token from GitHub

2. In the section where you add the Git repository URL , click Add under credentials and select Jenkins Credentials Provider. (refer Source code management — Git image)

3. Use your GitHub username and Personal Access Token (as the password).

Jenkins credentials provider

4. Save the credentials and select them in the repository settings.

4. Adding Build Steps

Executing a Java Program

  1. In the Build section, select Execute Windows batch command.
  2. Modify the following commands based on your project’s structure to compile and run the Java program:
javac hello\Hello.java
java hello.Hello
Build steps

3. Click Apply and Save.

5. Running the Jenkins Job

Building the Project

  1. Go to your Jenkins job and click Build Now.
  2. The job will start executing, and Jenkins will:
  • Fetch the latest code from the GitHub repository.
  • Compile the Java program.
  • Run the Java application.
Build the job

Checking the Console Output

  1. Click on the Build Number (#1, #2, etc.).
  2. Select Console Output to see the detailed execution logs.
Viewing the console output

AND.. you are done.

By integrating your GitHub repository with Jenkins as shown above, you can automate your build and deployment processes, ensuring faster and more reliable delivery of your software.

With continuous integration in place, your development pipeline becomes more efficient, allowing you to focus on writing great code while Jenkins handles the rest.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Published in Dev Genius

Coding, Tutorials, News, UX, UI and much more related to development

Written by Chamali Vishmani

... Writing as I learn ... | Associate Software Engineer @Vizuamatix | BSc Eng Hons Computer Engineering | CIMA Dip MA

No responses yet

Write a response