CI - CD With Jenkins
CI - CD With Jenkins
CI/CD WITH
JENKINS
- Rohan Thapa
thaparohan2019@gmail.com
What is Jenkins?
Jenkins is an open-source automation server
written in Java that helps automate parts of
software development related to building,
testing, and deploying, facilitating continuous
integration and continuous delivery (CI/CD).
Jobs
A job in Jenkins represents a task or a step in a
pipeline. Jenkins can have multiple jobs for
different stages in the pipeline (e.g., build,
test, deploy).
Key Concepts of Jenkins
Builds
A build is the result of executing a job. Builds
can represent compiled code or simply the
outcome of running automated tests.
On Windows:
Download Jenkins from the official website
and run the installer.
On Linux(Ubuntu/Debian):
Initial Setup and Unlocking Jenkins
After installation, Jenkins runs on
http://localhost:8080.
You will be prompted to enter an initial
admin password, which can be found in
the log file at:
Agent Types:
Static agents: Pre-configured machines or
VMs.
Dynamic agents: Can be spun up on-
demand (e.g., Docker containers,
Kubernetes pods).
Advanced Jenkins Concepts
Distributed Builds
Jenkins can distribute build jobs across
different machines to balance the load and
speed up the process.
Test:
Runs automated tests .
If tests pass, the pipeline moves forward.
Post:
Sends a Slack notification on both success
and failure. If successful, it sends a green
message; if the build fails, it sends a red
message.
Set up Wekbooks for Github
To trigger the pipeline whenever code is
pushed to GitHub, you need to set up a
webhook.
1. Go to your GitHub repository settings.
2. Select Webhooks and click Add webhook.
3. For the Payload URL, use
http://<JENKINS_URL>:<PORT>/github-
webhook/
4. Set Content type to application/json.
5. Choose Let me select individual events
and select Push.
Now, every time code is pushed to GitHub,
Jenkins will be notified and trigger the
pipeline.
Set up Wekbooks for Github
Format: https://jenkins-url/github-webhook/
Dockerfile Example
Your Dockerfile should be configured to build
and containerize your application. Here’s a
simple example for a Spring Boot application:
Deployment Setup
If uploading to cloud server:
Ensure you have Docker installed and
running on your remote server.
Set up SSH keys so Jenkins can SSH into
your server without a password.
In Jenkins, store the SSH credentials and
DockerHub login credentials in the Jenkins
credentials store.
Your deployment can either pull the latest
Docker image and run it or do a more
sophisticated deployment using
Kubernetes, Docker Swarm, or a similar
orchestration tool.
Configure for slack Notification
Install the Slack Notification Plugin from
the Jenkins Plugin Manager.
Configure the Slack plugin with your Slack
workspace and channel.
Create a Slack Webhook (go to Slack > Apps
> Custom Integrations > Jenkins CI).
Store your Slack workspace name and
credentials Jenkins credentials (slack-
credentials).
Result
Push code to Github