How to Integrate Git with Jenkins (Step-by-Step Tutorial)
- Viji Ravi
- Aug 31
- 4 min read
When you’re building modern software, automation is key. Manually compiling code, running tests, and deploying updates slows teams down and introduces errors. That’s where Continuous Integration (CI) comes in — a development practice where changes to code are automatically built, tested, and validated as soon as they’re committed.
Two of the most popular tools in this space are Git and Jenkins, and when combined, they create a powerful workflow:
· Git is a distributed version control system that tracks your project’s history and manages contributions from multiple developers.
· Jenkins is an open-source automation server designed to handle tasks like building, testing, and deploying applications.

By integrating Git with Jenkins, you can create a CI pipeline where every time developers push code to a repository, Jenkins automatically:
1. Pulls the latest changes.
2. Builds the project.
3. Runs tests to verify functionality.
4. Provides instant feedback on success or failure.
This integration eliminates the need for manual builds, catches issues early, and ensures that your main branch is always in a working state. In this tutorial, we’ll go step by step through the process of connecting Jenkins to Git, setting up triggers, and running your first automated build.
Things to know?
Before you start, make sure you have:
Jenkins installed and running (either locally or on a server).
Git installed on the same machine where Jenkins is running.
A Git repository hosted on GitHub, GitLab, Bitbucket, or a private server.
Basic admin access to Jenkins so you can install plugins and configure jobs.

Step 1: Install the Git Plugin in Jenkins
Go to Manage Jenkins → Plugins → Available plugins.
Search for Git Plugin.
Select it, click Install without restart, and restart Jenkins if prompted.
The Git plugin allows Jenkins to clone repositories, pull code, and work directly with Git as part of your build process.

Step 2: Configure Git in Jenkins
Next, make sure Jenkins knows where to find Git on your system:
Go to Manage Jenkins → Tools.
Scroll to the Git section.
Click Add Git and provide the installation path.
On Windows: git.exe
This ensures Jenkins can execute Git commands during builds.

Step 3: Create a New Jenkins Job
Now, let’s set up a job that will pull code from Git and build it:
1. From the Jenkins dashboard, click New Item.
2. Enter a project name (e.g., Jenkins_git_blog_demo).
3. Choose Freestyle Project. (good for beginners). For advanced pipelines, you can choose Pipeline instead.
4. Click OK.
This creates a new job that you can configure to integrate with Git.

Step 4: Connect Jenkins to Your Git Repository
1. Inside the job configuration, scroll down to Configurations → Source Code Management.
2. Select Git.
3. Enter your repository URL: https://github.com/VijayalakshmiR19/Jenkins_git_blog_demo.git
This tells Jenkins where to fetch your project’s source code.
If your repo is private, configure credentials in Jenkins:
Use SSH keys (recommended) for secure, passwordless authentication.
Or store an access token/password in Jenkins Credentials Manager.

Step 5: Configure Build Triggers
To make the build process automatic, you need to configure triggers. Jenkins offers two main options:
· Option 1: Poll SCM (Scheduled Check)
Select Poll SCM.
Enter a schedule using cron syntax, e.g.:
H/5 * * * *

(This checks for changes every 5 minutes).
Option 2: Webhook Trigger (Recommended)
In your GitHub/GitLab/Bitbucket repository settings, configure a webhook pointing to Github PUSH methods.
In Jenkins, enable GitHub hook trigger for GITScm polling.
Webhooks are faster and more efficient because Jenkins is notified instantly when changes are pushed.

Step 6: Create a simple bash script
This script will calculate print date / month
#!/bin/bash
# Simple unix commands
# Full date
echo "Today's full date is: $(date)"
# Current day
echo "Day: $(date +%d)"
# Current month (number)
echo "Month (number): $(date +%m)"
# Current month (name)
echo "Month (name): $(date +%B)"
# Current year
echo "Year: $(date +%Y)"
PUSH the script into Github

Step 7: Define Build Steps
Once Jenkins pulls your code, it needs instructions on what to do with it. The build steps vary by project type:
In my case, I've used the shell script for demo.
Generic Shell Script:
./Jenkins_git_blog_demo.sh
You can add multiple build steps if your pipeline requires testing, linting, packaging, or deployment.

Step 8: Run and Verify the Build
1. Save your job configuration.
2. On the job dashboard, click Build Now.
3. Monitor the Console Output to verify that Jenkins:
o Successfully cloned the Git repository.
o Ran the specified build steps.
o Reported results (success or failure).
If successful, you’ve just completed your first automated Git + Jenkins build!

FAQ :
Troubleshooting Common Issues
Repo URL Error: Double-check HTTPS/SSH format and credentials.
Git Not Found: Verify Git is installed and added to Jenkins Tools.
Permission Denied (SSH): Make sure Jenkins has the correct SSH keys configured.
Webhook Failing: Ensure your Jenkins server is accessible from the internet and not blocked by firewalls.
Best Practices for Git + Jenkins Integration
Use Jenkins Pipelines: Define your build process in a Jenkinsfile stored in Git for versioned CI/CD.
Secure Credentials: Store tokens and SSH keys in Jenkins Credentials Manager, never hard-code them.
Keep Builds Modular: Split builds into stages (build, test, deploy) for better visibility.
Use Agents: Distribute builds across multiple Jenkins agents to scale efficiently.
Monitor & Maintain: Regularly update plugins and Jenkins to avoid vulnerabilities.
Conclusion
By integrating Git with Jenkins, you’ve built the foundation of a powerful CI pipeline. Now every time code is pushed, Jenkins can automatically fetch changes, build the project, run tests, and provide feedback.
Next, consider enhancing your pipeline by:
Adding unit/integration tests (JUnit, PyTest, Mocha).
Deploying builds automatically to staging environments.
Using Jenkinsfile-based pipelines for full CI/CD automation.
With Git and Jenkins working together, your team can ship code faster, with fewer errors, and greater confidence.


