Skip to main content

Command Palette

Search for a command to run...

Jenkins

Jenkins Explained: A Complete Guide

Updated
9 min read
T

Learning DevOps Engineer passionate about cloud computing, containerization, and automation. Currently exploring Docker, AWS, and CI/CD pipelines to build scalable and efficient workflows. Documenting my learning journey in blog. stay tuned with me for learning.

Jenkins is an open-source automation server used primarily for continuous integration and continuous delivery (CI/CD). It helps automate the building, testing and deploying of applications, which is especially useful in DevOps w`

Workflows.

CI/CD : Continuous Integration and Continuous Delivery

Setting Up Java, Git, Maven on Windows for Jenkins

install and configure Java (JDK), Git, Maven, and Jenkins on a Windows machine.

Install & Configure Git

Git is a version control tool and is widely used with Jenkins.

  1. Download Git for Windows from https://git-scm.com/downloads/win.

  2. For windows Git for Windows/x64 Portable. (as per your windows machine).

  3. Install it.

  4. after installation - Git Bash

  5. Configure your details :

git config --global user.name "your_name"
git config --global user.email "your_email"
git config --global --list
git --version

Install & Configure Java (JDK)

Jenkins and Maven require Java to run, so let’s begin here.

  1. Download JDK (Windows .exe installer).

  2. https://download.oracle.com/java/21/latest/jdk-21_windows-x64_bin.exe.

  3. Install it (default path: C:\Program Files\Java\jdk-XX).

  4. Configure environment variables :
    Add JAVA_HOMEC:\Program Files\Java\jdk-XX
    Add bin path to PATH.

  5. Configure your details :

    echo %JAVA_HOME%
    java --version
    

    Note: Jenkins currently supports JDK 17 and 21. Avoid using JDK 24.

Install & Configure Maven

Maven is a build automation tool often integrated with Jenkins.

  1. Download Maven from apache.org.

  2. https://dlcdn.apache.org/maven/mvnd/1.0.2/maven-mvnd-1.0.2-windows-amd64.zip

  3. Extract it to a directory.

  4. Set environment variables :
    MAVEN_HOME = C:\apache-maven
    Add %MAVEN_HOME%\bin to PATH.

  5. Configure your details :

    mvn -version
    

    Reboot system

Install & Configure Jenkins

Jenkins is the backbone of DevOps automation.

  1. Download Jenkins Windows installer (.msi) from jenkins.io.

  2. https://2.mirrors.in.sahilister.net/jenkins/windows-stable/2.516.2/jenkins.msi

  3. Install → it auto-detects Java.

  4. Open Jenkins in your browser :

    http://localhost:8080
    
  5. Create an admin user → install suggested plugins → dashboard will appear.

To avoid issues, follow this installation sequence :

  • Git

  • Java (JDK 17 or 21)

  • Maven

  • Reboot System

  • Jenkins

Understanding Manage Jenkins and Core Settings

Manage Jenkins

  • System : Configure global setting and path.

  • Tools : Configure tools, their locations and automatic installers.

  • Plugins : Add, remove, disable or enable plugins that can extend the functionality of Jenkins.

  • Nodes : Add, remove, control and monitor the various nodes that Jenkins runs jobs on.

  • Clouds : Add, remove and configure cloud instances to provision agents on-demand.

  • Appearance : Configure the look and feel of Jenkins.

Security

  • Security : Secure Jenkins define who is allowed to access/use the system.

  • Credentials : Configure credentials.

  • Credential providers : Configure the credential providers and types.

  • Users : Create/delete/modify users that can log in to this Jenkins.

Create a first Jenkins job

  1. Click New Item or Create a job.

  2. Name → Give your job name (e.g., demo-job).

  3. Select a type : Freestyle project or Pipeline .

  4. Click OK.

  5. Configure the Job

  6. Description - optional

  7. Build Steps → Click Add build step → Choose Execute shell (Linux) or Execute Windows batch command.

    echo "Hello, Jenkins! My first job is running."
    pwd 
    ls
    
  8. Click Save.

  9. On the job page, click Build Now.

  10. On the left, under Build History, click the build number (#1).

  11. Click Console Output to see the result.

You see

Hello, Jenkins! My first job is running.
Finished: SUCCESS

How to create a user in Jenkins and why ?

Creating a new user depends on whether you have security enabled (like Matrix-based security, Role-based authorization, etc.). I’ll walk you through the basic way (default Jenkins security).

  1. Go to Manage Jenkins.

  2. Under Security, click Users.

  3. Click Create User.

  4. Username → Example: devuser

  5. Password → (Set a secure password)

  6. Confirm password

  7. Full name → Example: DevOps Engineer

  8. Email address → Example: devuser@example.com

  9. Click Create User.

Use of Git Plugin + Build Workflow

  1. Click New Item or Create a job.

  2. Name → Give your job name (e.g., demo-Gittest).

  3. Select a type : Freestyle project.

  4. Click OK.

  5. Description - optional

  6. Source Code Management → Git

  7. Repositories → Repository URL → Copy the repository URL (HTTP).

  8. Branches to build → Branch Specifier (blank for 'any').

  9. Build Steps → Click Add build step → Choose Execute shell (Linux) or Execute Windows batch command.

  10. Click Save.

  11. On the job page, click Build Now.

  12. On the left, under Build History, click the build number (#1).

  13. Click Console Output to see the result.

Build periodically

This feature is useful for running automated tasks at fixed time intervals, regardless of whether changes have been committed to your sources code repository.

  1. Click New Item or Create a job.

  2. Name → Give your job name (e.g., Build-periodically).

  3. Select a type : Freestyle project.

  4. Click OK.

  5. Description - optional

  6. Source Code Management → None or Git.

  7. Triggers → Build periodically (Select the checkbox. Check this box to schedule your job to run automatically at specific times).

  8. Schedule → Example……

    H 0 * * *   → runs every day at midnight
    H */2 * * * → runs every 2 hours
    
  9. Click Save.

  10. On the job page, click Build Now.

  11. On the left, under Build History, click the build number (#1).

  12. Click Console Output to see the result.

Poll SCM - Periodically check the Source Code Management repository for changes.

If Jenkins detects new commits or code changes. It automatically triggers new build.

  1. Click New Item or Create a job.

  2. Name → Give your job name (e.g., Poll-SCM).

  3. Select a type : Freestyle project.

  4. Click OK.

  5. Description - optional.

  6. Source Code Management → Git

  7. Repositories → Repository URL → Copy the repository URL (HTTP).

  8. Branches to build → Branch Specifier (blank for 'any').

  9. Triggers → Poll SCM → Schedule → Example……

    H/5 * * * *   →  check every 5 minutes for changes
    
  10. Click Save.

  11. On the job page, click Build Now. (Jenkins does not build on a schedule here. It only builds when it detects changes in the repository.)

  12. On the left, under Build History, click the build number (#1).

  13. Click Console Output to see the result.

Parameterized jobs in Jenkins

  1. String Parameter : Example Use: BRANCH_NAME = main

  2. Boolean Parameter : Example Use: RUN_TESTS = true

  3. Choice Parameter : Example Use: Choices: DEV, QA, PROD

  4. Password Parameter : Example Use: DB_PASSWORD

  5. File Parameter : Example Use: Configuration file for deployment.

How to Add Parameters to a Jenkins Job

  1. Go to the Jenkins job → Click Configure.

  2. Check This project is parameterized.

  3. Click Add Parameter → Choose the type (String, Boolean, Choice, Password, File.).

  4. Save the job.

  5. Using Parameters in a Job

  6. Build Steps → Click Add build step → Choose Execute shell (Linux) or Execute Windows batch command.

  7.         echo "Branch selected: $BRANCH_NAME"
            git checkout $BRANCH_NAME
    

    Click Save.

  8. On the job page, click Build Now.

  9. On the left, under Build History, click the build number (#1).

  10. Click Console Output to see the result.

Timeout

Jobs automatically stop a build if it takes longer than the specified time. This helps prevent jobs from hanging forever due to issues like infinite loops.

  • Absolute : Example:

    • Timeout set to 30 minutes → build is aborted after 30 minutes regardless of normal build duration.
  • Deadline : Example:

    • If the deadline is set to 6:00 AM → even if a job started at 5:50 AM, it will be killed at 6:00 AM.
  • Elastic : Example:

    • Last 5 builds average = 10 mins

    • Elastic factor = 2

    • Timeout = 20 mins

  • Likely Stuck : Example:

    • Average duration = 10 mins

    • Build has been running 1 hour → Jenkins aborts it.

  • No Activity : Example:

    • No console output for 5 minutes → Jenkins kills the job.

How to create a Timeout.

  1. Click New Item or Create a job.

  2. Name → Give your job name (e.g., Poll-SCM).

  3. Select a type : Freestyle project.

  4. Click OK.

  5. Environment → Terminate a build if it's stuck (Select the checkbox).

  6. Time-out strategy → Choose the type (Absolute, Deadline, Elastic, Likely Stuck, No Activity).

  7. Build Steps → Click Add build step → Choose Execute shell (Linux)

    sleep 240
    
  8. Click Save. and click Build Now.

    You see

    Build timed out (after 3 minutes). Marking the build as aborted.
    Terminated
    Build was aborted
    Finished: ABORTED
    

SMTP Server

Install the Required Plugins :

  • Mailer Plugin.

  • Email Extension Plugin

Configure SMTP Server

  1. Go to Manage JenkinsSystemE-mail Notification.

  2. SMTP serversmtp.gmail.com

  3. Click Advanced.

  4. Use SMTP Authentication. (Select the checkbox).

  5. User Name → e.g., jenkins@example.com

  6. Password → App Password if using Gmail and turn on 2-Step Verification was turned on

  7. Use SSL. (Select the checkbox).

  8. SMTP Port → SMTP Port 465 (SSL) or 587 (TLS).

Add Email Notification in a Freestyle Job.

  1. Open a Job → Configure.

  2. Scroll to Post-build Actions.

  3. Choose E-mail Notification.

  4. Recipients → Enter recipient email IDs (developer@example.com).

  5. Send e-mail for every unstable build. (Select the checkbox).

  6. Click Save .

pipeline build log :

  1. Click New Item or Create a job.

  2. Name → Give your job name (e.g., Poll-SCM).

  3. Select a type : pipeline.

  4. Click OK.

  5. Configure the Pipeline → Pipeline Script → try simple hello world .

  6.   pipeline {
          agent any
      
          stages {
              stage('Hello') {
                  steps {
                      echo 'Hello World'
                  }
              }
          }
      }
    
  7. Save and build .

Set Global Environment Variables via Jenkins UI

  1. Click Manage Jenkins.

  2. Click Configure System.

  3. Scroll to the section Global properties.

  4. Check the box Environment variables.

  5. Click Add and enter:

    • Name: variable name

    • Value: variable value

  6. Click Save at the bottom.

Job-specific environment variables

  1. Open your Jenkins job → Configure

  2. Build Steps → Execute shell

  3.   echo $variable name
    
  4. Save and Build .

Runs multiple shell commands together

sh '''
    echo "first"
    echo "this is first build"
'''

Retries commands

retry(count) {
    sh 'echo retrying welcome'
}

Cancels this block if it runs longer

timeout(time: 15, unit: 'SECONDS') {
     sh 'sleep 30'
}