Getting Started With Jenkins

Search for a command to run...

No comments yet. Be the first to comment.
What is AWS? What is Cloud Computing? Cloud computing is the practice of using computing resources over the internet instead of owning and maintaining physical hardware. These resources include: Virtual servers Storage systems Databases Networkin...

Introduction In modern software development, shipping code quickly and reliably is just as important as writing the code itself. This is where CI/CD comes into play. Continuous Integration (CI) ensures that every code change is tested and validated a...

Introduction What is shell scripting? Shell scripting is writing a sequence of commands for the command-line shell (most commonly Bash on Linux) into a text file so they run automatically. Instead of typing commands one by one, you save them as a scr...

Introduction TimescaleDB is an open-source database that's specifically designed for time-series data, which is data that is recorded over time, like sensor readings, stock prices, or application metrics. The simplest way to think about it is as a sp...

Jenkins is an open-source automation server that helps automate the process of building, testing, and deploying applications.
In simple words, it is a tool that runs tasks automatically so developers don’t have to do them manually again and again.
Jenkins is mainly used to enable CI/CD (Continuous Integration and Continuous Delivery).
This means:
Every time developers push code, Jenkins automatically checks it.
It builds the project, runs tests, and reports errors quickly.
It can also deploy the project automatically to servers.
To save time by automating repetitive tasks
To detect bugs early
To make deployments faster and safer
To improve team productivity
To maintain consistent software delivery
Jenkins is widely used in DevOps because it simplifies and accelerates the software development and delivery process. Below are the core benefits:
Jenkins is primarily used to implement CI/CD pipelines.
Continuous Integration (CI):
Whenever a developer pushes code, Jenkins automatically fetches the latest changes, builds the project, and runs tests. This ensures errors are detected early in the development cycle.
Continuous Delivery (CD):
After successful testing, Jenkins can automatically deploy the application to servers or cloud environments, enabling smooth and consistent delivery.
Before Jenkins, build, test, and deployment processes were performed manually, which was slow and error prone.
Jenkins automates these repetitive tasks, including:
Code compilation
Running test suites
Deploying applications
Running scripts or commands
Generating reports
Automation significantly reduces manual effort and increases team productivity.
With automated checks and deployments, developers receive quicker feedback, and applications can be delivered faster.
This leads to:
Faster release cycles
Early bug detection
More reliable deployments
Improved overall development efficiency
Jenkins follows a simple yet powerful architecture consisting of two main components: the Controller (Master) and Agents (Nodes). Understanding these components helps explain how Jenkins executes jobs efficiently.

The Jenkins Controller is the central part of the system. Its responsibilities include:
Managing the Jenkins UI and dashboard
Scheduling and distributing jobs
Maintaining configurations, plugins, and security settings
Monitoring overall system health
Although the controller can run jobs, its primary role is coordination and management.
Agents are machines (physical or virtual) that execute the actual tasks assigned by the controller.
An agent can run on:
A local machine
A remote Linux/Windows server
A Docker container
A cloud instance
Agents help distribute workloads, allowing multiple jobs to run in parallel and improving performance.
The basic flow of job execution in Jenkins is:
A developer pushes code to the source repository (e.g., GitHub).
Jenkins detects the change through a trigger or scheduled check.
The controller assigns the job to an available agent.
The agent pulls the latest code, builds it, and executes the defined steps (tests, scripts, deployments, etc.).
The agent sends the results back to the controller.
The controller displays build status, logs, and reports on the Jenkins dashboard.
There are multiple ways to install Jenkins, but using Docker is one of the simplest and most efficient methods, especially for beginners. Below is a recommended approach followed by the basic setup steps.
Docker allows you to run Jenkins in an isolated container without manually configuring system dependencies.
Command to run Jenkins using Docker:
docker run -p 8080:8080 -p 50000:50000 jenkins/jenkins:lts
This command:
Pulls the Jenkins LTS (Long-Term Support) image
Exposes port 8080 for accessing Jenkins
Exposes port 50000 for agent communication
Starts Jenkins inside a container
Once the container is running, you can access Jenkins in a browser at:
http://localhost:8080
After starting Jenkins for the first time, follow these setup steps:
Unlock Jenkins:
Jenkins provides an initial admin password. You can retrieve it using the Docker logs or by checking the Jenkins home directory inside the container.
Install Suggested Plugins:
Jenkins recommends a default set of plugins needed for common tasks. Installing them ensures essential features are available immediately.
Create an Admin User:
Set up a username, password, and email that you will use to log in.
Configure Instance Settings:
Confirm the Jenkins URL and any other basic settings displayed during setup.
Jenkins is Ready:
After completing these steps, Jenkins will redirect you to the dashboard, where you can start creating jobs.
Once Jenkins is installed and set up, the dashboard serves as the central interface for managing and monitoring all activities. Understanding the main sections of the dashboard helps you navigate Jenkins effectively.

This panel provides access to essential options such as:
New Item: Create a new job or pipeline
People: View user information
Build History: View previously executed jobs
Manage Jenkins: Configure system settings, plugins, security, and tools
My Views: Create custom dashboard views
Credentials: Store and manage secrets (passwords, tokens, SSH keys)
The central area displays all existing Jenkins jobs. For each job, you can see:
Job name
Current build status
Last build result
Build activity trends
This section provides a quick overview of ongoing and past tasks.
Shows a timeline of recent builds with their status:
Successful (blue/green)
Failed (red)
Unstable (yellow)
You can click on any build to view detailed logs and results.
This is the most important administrative section, where you can:
Install or update plugins
Manage global settings
Configure tools (JDK, Maven, Git)
Manage nodes and agents
Apply security settings
Backup and restore configurations
Provides detailed insights into system performance, environment variables, and Jenkins logs. Useful for troubleshooting.
Creating a basic job in Jenkins helps you understand how automation works within the system. One of the simplest ways to get started is by creating a Freestyle Project.
From the Jenkins dashboard, click New Item on the left panel.
Provide a meaningful name for the job, for example:
First-Jenkins-Job
Choose the Freestyle Project option and click OK.
Add a short description if needed.
This helps identify the job’s purpose.
If you want Jenkins to pull code from GitHub or any repository, enter the repository URL here.
This step is optional for a simple test job.
Scroll down to the Build section and click Add build step → Execute shell (or Execute Windows batch command).
Add a simple command such as:
echo "Hello from Jenkins"
This verifies that Jenkins can run shell commands.

Click Save.
Click Build Now on the left side.
A new build will appear in the Build History section.
Click on the build number (e.g., #1).
Then click Console Output to view:
The executed commands
The output generated
Success/failure status
If everything is configured correctly, the console will display:
Hello from Jenkins

Jenkins Pipelines allow you to define your entire build, test, and deployment process as code. This approach is more flexible and maintainable than traditional Freestyle projects.
A Jenkins Pipeline is a set of automated steps written as code that defines how your application should be built, tested, and deployed.
Pipelines are written using a file called the Jenkinsfile, which is stored inside the project’s repository. This makes your CI/CD process version controlled and portable.
More structured and beginner friendly
Uses a predefined syntax
Recommended for most use cases
Example:
pipeline {
agent any
stages {
stage('Build') {
steps {
echo "Building the application"
}
}
stage('Test') {
steps {
echo "Running tests"
}
}
}
}
More flexible
Uses full Groovy scripting
Preferred for advanced automation
Not required for beginners
1. Agent
Specifies where the pipeline will run (any agent, specific node, or Docker container).
2. Stages
Represents major phases of the pipeline such as build, test, deploy.
3. Steps
Commands executed inside each stage, for example:
Shell commands
Scripts
Tool executions
4. Post Section
Defines actions that should run after the pipeline completes (success or failure).
The pipeline is stored as code inside the repository
Easier to review, update, and maintain
Supports complex workflows
Reliable and repeatable builds
Essential for real-world CI/CD setups
Integrating Jenkins with Git or GitHub allows Jenkins to automatically pull the latest code changes and build the project whenever updates are made. This integration is a core part of Continuous Integration (CI).
Before integrating:
Jenkins must have the Git plugin installed.
Git should be installed on the Jenkins agent (or controller if jobs run there).
You should have a GitHub repository URL available.
Go to the job where you want to set up Git integration, or create a new job.
Inside the job configuration page, scroll to the Source Code Management section and select Git.
Paste your GitHub repository URL, for example:
https://github.com/username/repository.git
If the repository is private, you will need to add credentials from Jenkins → Credentials.
Specify the branch Jenkins should use, typically:
*/main
or
*/master
Webhooks allow GitHub to notify Jenkins automatically when code is pushed.
Open your GitHub repository.
Go to Settings → Webhooks → Add webhook.
Add your Jenkins webhook URL:
http://<jenkins-server-url>/github-webhook/
Select Just the push event.
Save the webhook.
Now, every time code is pushed, Jenkins gets notified immediately.
After you configure Git:
Trigger a Build Now from Jenkins.
Jenkins will clone the repository.
You can view the Git commands and output inside the Console Output.
This integration ensures your build pipeline always uses the latest code and supports fully automated CI workflows.
Build triggers in Jenkins define when and how a job should start automatically. Instead of manually clicking “Build Now,” you can instruct Jenkins to run jobs based on specific conditions or events. This is an essential part of CI/CD automation.
This is the simplest method where you manually start a build by clicking Build Now.
Useful for testing or on demand tasks.
Using GitHub webhooks, Jenkins can automatically start a job whenever code is pushed to the repository.
Process:
Developer pushes code
GitHub sends a notification to Jenkins
Jenkins pulls the latest code and runs the job
This is widely used in Continuous Integration pipelines.
Jenkins periodically checks the repository for any changes. If it detects a change, it triggers a build.
Example schedule (every 5 minutes):
H/5 * * * *
This option does not require webhooks, but it is less efficient since Jenkins actively checks the repository.
You can schedule jobs using CRON syntax.
Examples:
Every day at midnight:
0 0 * * *
Every 15 minutes:
H/15 * * * *
Useful for periodic tasks like backups, scans, cleanup jobs, or nightly builds.
A job can be configured to run automatically after another job finishes.
Example:
Job A builds the code
Job B automatically deploys it after Job A succeeds
This helps create multi-step pipelines.
Reduce manual work
Ensure faster feedback to developers
Maintain continuous and automated workflows
Enable reliable CI/CD processes
Jenkins’ power comes largely from its extensive plugin ecosystem. Plugins extend Jenkins’ capabilities, allowing integration with various tools, environments, and workflows. As a fresher, knowing the most commonly used plugins is sufficient to get started.
Enables Jenkins to interact with Git repositories.
Supports cloning, pulling, and managing branches.
Essential for CI/CD pipelines that depend on version control.
Provides support for Jenkins Pipeline as code (Jenkinsfile).
Allows defining build, test, and deployment stages in a structured way.
Necessary for creating Declarative and Scripted pipelines.
Simplifies integration with GitHub repositories.
Supports webhooks for automatic build triggers on code pushes.
Provides status reporting back to GitHub.
Enables Jenkins to build and run Docker containers.
Useful for containerized applications and DevOps workflows.
Allows sending email notifications based on build results.
Can be configured to alert developers in case of build failures.
Sends build notifications to Slack channels.
Useful for team collaboration and monitoring build status.
Extend Jenkins’ functionality to fit your project needs
Simplify integration with other tools
Enable automation beyond basic builds
Make Jenkins suitable for real-world CI/CD pipelines