How to Connect Jenkins with Git for Continuous Integration?

Table of Contents

Recommended Learning Path

How to Connect Jenkins with Git for Continuous Integration

Connect Jenkins with Git

Introduction

When developers update application code, the changes need to be checked before they become part of a software release. Manually downloading the latest code and running tests after every update can be repetitive.

Jenkins Git integration helps automate this process by connecting source-code repositories with continuous integration pipelines.

When developers push changes to GitHub, Jenkins can retrieve the latest code and execute configured build and testing steps.

This guide explains how to connect Jenkins with Git, configure a Jenkinsfile, set up GitHub webhooks, and verify an automated CI workflow.

Quick Answer: How Does Jenkins Git Integration Work?

Jenkins Git integration connects a Git repository to Jenkins so that source-code changes can trigger automated build and testing processes.

A typical workflow is:

Developer → Git Push → GitHub → Jenkins Webhook → Git Checkout → Build → Test

Git manages source-code versions, while Jenkins executes the automation.

Once configured, this workflow allows developers to identify integration issues without manually running every build.

Why Is Git Important in Continuous Integration?

Git is a distributed version control system used to track changes in source-code files.

Developers use Git to create branches, commit changes, and collaborate on applications.

Jenkins complements Git by automating tasks after changes are submitted.

For example, when a developer updates a Java application, Jenkins can retrieve the code and run Maven commands to compile and test it.

The roles are different:

Git: Stores and tracks code changes.

Jenkins: Automates builds, tests, and other configured operations.

Together, they form an important part of a Jenkins CI/CD workflow.

Your DevOps Journey Starts Here Explore the DevOps Roadmap

What Tools Are Required?

Tool

Purpose

Git

Version control

GitHub

Hosts the example repository

Jenkins

Automates continuous integration

Jenkins Git Plugin

Integrates Git repositories

GitHub Plugin

Supports GitHub webhook triggers

Jenkinsfile

Defines the automation pipeline

Node.js

Runs the example application check

The same integration concept can be used with Java, Python, Node.js, and other technologies.

Azure Pipelines can also deploy to virtual machines, containers, Kubernetes, and other environments. This tutorial focuses on Azure App Service.

Prerequisites for Jenkins Git Integration

Before starting, prepare:

  • A working Jenkins installation
  • A GitHub account
  • Git installed on the Jenkins build agent
  • Required Jenkins plugins
  • Permission to create Jenkins jobs
  • A repository containing sample application files
  • Node.js installed on the build agent for this example

For webhook automation, GitHub must be able to reach the Jenkins webhook endpoint through a properly secured network connection.

A Jenkins server accessible only at localhost cannot directly receive GitHub’s public webhook requests without additional supported connectivity.

Step-by-Step Jenkins Git Integration

This example uses a simple Node.js file to demonstrate automatic validation.

Step 1: Prepare a GitHub Repository

Create a GitHub repository named:

jenkins-git-demo

Add a file named app.js:

function greet(name) {

  return `Hello, ${name}!`;

}

 

console.log(greet(“DevOps”));

Commit the file to the main branch.

Copy the repository HTTPS URL.

For example:

https://github.com/USERNAME/jenkins-git-demo.git

Replace USERNAME with your GitHub username.

Step 2: Install the Required Jenkins Plugins

Open the Jenkins dashboard.

Navigate to:

Manage Jenkins → Plugins

Check that the following plugins are installed:

  • Git Plugin
  • Git Client Plugin
  • Pipeline
  • GitHub Plugin

Install missing plugins and restart Jenkins if required.

The Git Plugin enables repository checkout, while the GitHub Plugin supports webhook integration.

Step 3: Configure Git Credentials

For a public repository, Jenkins may be able to retrieve the code without authentication.

For private repositories, configure appropriate credentials.

Open:

Manage Jenkins → Credentials

Select an appropriate credential store and scope.

For HTTPS repository access, configure a username/password credential using your GitHub username and a suitable personal access token as the password.

For SSH access, configure an SSH private key credential.

Give the credential a recognizable ID, such as:

github-repo-access

Use credentials with only the permissions required to read the intended repository.

Never put authentication tokens directly into a Jenkinsfile.

Step 4: Create a Jenkinsfile

In the repository root, create a file named:

Jenkinsfile

Add:

pipeline {

    agent any

 

    stages {

        stage(‘Checkout’) {

            steps {

                checkout scm

            }

        }

 

        stage(‘Build’) {

            steps {

                sh ‘node –version’

            }

        }

 

        stage(‘Test’) {

            steps {

                sh ‘node –check app.js’

            }

        }

    }

}

This example uses a Linux or Unix-like Jenkins agent with Node.js installed.

The checkout scm instruction retrieves the source revision associated with the Pipeline’s configured repository.

The build stage checks Node.js availability, while the test stage validates JavaScript syntax.

Note: This is a basic CI demonstration. A real application should include meaningful build commands, unit tests, and integration tests.

Step 5: Create a Jenkins Pipeline Job

Open the Jenkins dashboard and select New Item.

Enter a name such as:

Jenkins-Git-CI

Choose Pipeline and select OK.

In the Pipeline configuration:

  1. Select Pipeline script from SCM.
  2. Choose Git as the SCM.
  3. Enter the GitHub repository URL.
  4. Select credentials if the repository is private.
  5. Configure the intended branch, such as */main.
  6. Set the script path to Jenkinsfile.
  7. Save the job.

Jenkins can now retrieve the Pipeline configuration directly from Git.

Step 6: Run the First Build

Open the Jenkins Pipeline job and select Build Now.

Jenkins retrieves the repository and executes the stages defined in the Jenkinsfile.

Check the build’s console output.

A successful run should show that the repository was checked out and the configured commands completed.

If the build fails, inspect the console output to identify the failing stage.

Step 7: Configure a GitHub Webhook

Manual builds are useful for testing, but continuous integration is more useful when builds start automatically.

Open the GitHub repository.

Navigate to:

Settings → Webhooks → Add webhook

Enter the Jenkins endpoint:

https://YOUR-JENKINS-DOMAIN/github-webhook/

Set the content type to:

application/json

Select the push event, then save the webhook.

In Jenkins, open the Pipeline job’s configuration.

Under Build Triggers, enable:

GitHub hook trigger for GITScm polling

Save the configuration.

The GitHub Plugin uses incoming webhook notifications to identify relevant repository changes and trigger the configured Jenkins job.

Use HTTPS and follow your organization’s security requirements when exposing Jenkins to webhook traffic.

Step 8: Test Jenkins Git Automation

Update the message in app.js:

console.log(greet(“Jenkins CI”));

Commit and push the update:

git add app.js

git commit -m “Update demo message”

git push origin main

Check the GitHub webhook’s recent deliveries and the Jenkins build history.

If the integration works, Jenkins should start a new build and execute the configured validation steps.

This demonstrates Jenkins Git pull automation through repository checkout.

Dreaming of a DevOps Career?  Start Your DevOps Career

Common Jenkins Git Integration Errors

Problem

Possible cause

What to check

Repository checkout fails

Incorrect repository URL

Git URL and branch

Authentication fails

Invalid credentials

Token or SSH permissions

Git not found

Git missing on agent

Agent installation and tool configuration

Jenkinsfile not found

Incorrect script path

File name and location

Webhook does not trigger

Endpoint unreachable

URL, HTTPS, webhook deliveries

Build fails

Missing runtime or code error

Agent tools and console output

Always check the Jenkins console output before changing unrelated configuration settings.

Jenkins Git Integration Best Practices

Use Secure Credentials

Store tokens and SSH keys in the Jenkins credential system with appropriately restricted permissions.

Protect the Jenkins Server

Use HTTPS, proper access controls, and a supported security configuration.

Automate Tests

Run relevant tests whenever source code changes.

Use Branch-Based Workflows

Separate development and production branches where appropriate.

Maintain Jenkinsfiles in Git

Keeping the Pipeline configuration in source control makes it easier to review and maintain alongside application code.

Review Plugin Updates

Use supported Jenkins and plugin versions and regularly review security advisories.

FLM Expert Perspective: The C-T-V Framework

Beginners can understand Jenkins Git integration through three stages.

C — Connect: Establish repository access and checkout.

T — Trigger: Configure when Jenkins should start a build.

V — Validate: Run checks and inspect results.

Connect → Trigger → Validate

This framework helps learners identify whether a failure occurred during repository access, automatic triggering, or build validation.

Beginner Learning Roadmap

Stage

What to learn

1

Git and GitHub fundamentals

2

Jenkins installation and setup

3

Git Plugin configuration

4

Jenkins credentials

5

Jenkinsfile and Pipeline stages

6

GitHub webhook integration

7

Automated testing

8

Docker integration

9

AWS or Azure deployment

After completing this example, try creating a Java Maven Pipeline that compiles and tests a simple application.

This provides more practical experience with automated continuous integration.

Frequently Asked Questions

1. What is Jenkins Git integration?

It connects Jenkins to a Git repository so code changes can be retrieved and validated automatically.

2. Why is Git used with Jenkins?

Git manages source-code versions, while Jenkins automates builds and tests.

3. Which Jenkins plugin supports Git?

The Jenkins Git Plugin supports common Git operations, including repository checkout.

4. Can Jenkins connect to private GitHub repositories?

Yes. Jenkins can use appropriately configured HTTPS or SSH credentials.

5. What is a Jenkinsfile?

A Jenkinsfile defines a Jenkins Pipeline as code and is commonly stored in the application’s repository.

6. What is checkout scm?

It retrieves source code using the SCM configuration associated with the Pipeline.

7. What is a Jenkins Git webhook?

A webhook notifies Jenkins about repository events, helping trigger automated builds.

8. Does Jenkins automatically build after every commit?

Only when suitable triggers are configured. A local commit alone does not necessarily trigger Jenkins.

9. Is Jenkins Git integration part of CI/CD?

Yes. It provides a foundation for automated building, testing, and potentially deployment.

10. Can Jenkins work with AWS and Azure?

Yes. Jenkins can integrate with AWS and Azure using supported plugins, APIs, tools, and deployment configurations.

Conclusion

Jenkins Git integration connects version control with automated continuous integration.

By linking a GitHub repository to Jenkins, configuring a Jenkinsfile, and enabling webhook triggers, beginners can understand how code changes move through automated validation.

The key stages are:

Git Push → Jenkins Trigger → Checkout → Build → Test

Start with a small repository, confirm that manual builds succeed, and then configure webhook-based automation.

Once comfortable, add automated tests, Docker image creation, and cloud deployment.

Learners interested in structured cloud and automation practice can learn DevOps in Telugu while building their own Jenkins CI/CD projects.

Get Interview-Ready for DevOps Prepare for DevOps Interviews

First 2M+ Telugu Students Community