DevOps / CI/CD (Continuous Integration and Continuous Deployment)
Configuring Jenkins for CI/CD
This tutorial will guide you through the process of setting up Jenkins, a popular open-source tool used for continuous integration and delivery. You will learn how to configure Je…
Section overview
5 resourcesCovers automating software delivery pipelines to enable continuous integration and continuous deployment.
1. Introduction
In this tutorial, our main goal is to configure Jenkins for Continuous Integration/Continuous Delivery (CI/CD). Jenkins is an open-source automation server that allows you to automate different stages of your delivery pipeline. You will learn how to set up Jenkins, create a simple pipeline, and integrate it with a version control system.
You will learn how to:
- Install Jenkins
- Configure Jenkins
- Create a Jenkins pipeline
- Integrate Jenkins with GitHub
Prerequisites:
- Basic knowledge of version control systems, preferably Git
- Java installed on your system
- A GitHub account
2. Step-by-Step Guide
2.1 Installing Jenkins
First, you need to install Jenkins. Here are the steps to install Jenkins on Ubuntu:
- Update your system with
sudo apt update - Install Java Development Kit with
sudo apt install openjdk-11-jdk - Add the Jenkins Debian repository with
wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add - - Append the Debian package repository address to the server's sources.list:
echo deb http://pkg.jenkins.io/debian-stable binary/ | sudo tee /etc/apt/sources.list.d/jenkins.list - Update the apt package list and install Jenkins
sudo apt update && sudo apt install jenkins
After installation, Jenkins service will start automatically. You can check its status using systemctl status jenkins
2.2 Configuring Jenkins
Open your web browser and navigate to http://localhost:8080. You'll see a Unlock Jenkins page. To find the password, use the command sudo cat /var/lib/jenkins/secrets/initialAdminPassword. Copy the password, paste it into the form, and click Continue.
Next, you'll be prompted to customize Jenkins. For this tutorial, select Install suggested plugins. Jenkins will then install the suggested plugins.
2.3 Creating a Jenkins Pipeline
Once Jenkins is configured, you need to create a new job. On the Jenkins dashboard, click on New Item. In the next screen, enter a name for the job, select Pipeline, and click OK.
In the pipeline configuration page, scroll down to the Pipeline section. Here, you can define your pipeline script. For simplicity, we'll create a pipeline that prints a simple message.
pipeline {
agent any
stages {
stage('Stage 1') {
steps {
echo 'Hello, Jenkins!'
}
}
}
}
Click Save to finish creating the pipeline.
2.4 Integrating Jenkins with GitHub
To integrate Jenkins with GitHub, you need to install the GitHub plugin. Go to Manage Jenkins > Manage Plugins > Available, then find and select GitHub plugin. Click on Install without restart.
After installing the plugin, go to your job configuration page and in the Pipeline section, select Pipeline script from SCM. Then, select Git and enter your repository URL.
3. Code Examples
Here's an example of a Jenkins pipeline that clones a Git repository and builds a Java project with Maven. The example assumes you have a Maven project in your repository.
pipeline {
agent any
stages {
stage('Clone repository') {
steps {
git 'https://github.com/your-repository.git'
}
}
stage('Build') {
steps {
sh 'mvn clean install'
}
}
}
}
4. Summary
In this tutorial, you've learned how to install and configure Jenkins, create a simple pipeline, and integrate Jenkins with GitHub. To expand your knowledge, you can explore how to use Jenkins with other version control systems, and how to configure complex pipelines.
5. Practice Exercises
Exercise 1: Install Jenkins on your local machine and create a simple pipeline that prints a message.
Exercise 2: Create a Jenkins pipeline that clones a Git repository and lists the files in the repository.
Exercise 3: Create a Jenkins pipeline that clones a Git repository, builds a Java project with Maven, and archives the build results.
Remember, practice is the key to mastering any skill. Keep experimenting with different pipeline configurations and Jenkins features.
Need Help Implementing This?
We build custom systems, plugins, and scalable infrastructure.
Related topics
Keep learning with adjacent tracks.
Popular tools
Helpful utilities for quick tasks.
Latest articles
Fresh insights from the CodiWiki team.
AI in Drug Discovery: Accelerating Medical Breakthroughs
In the rapidly evolving landscape of healthcare and pharmaceuticals, Artificial Intelligence (AI) in drug dis…
Read articleAI in Retail: Personalized Shopping and Inventory Management
In the rapidly evolving retail landscape, the integration of Artificial Intelligence (AI) is revolutionizing …
Read articleAI in Public Safety: Predictive Policing and Crime Prevention
In the realm of public safety, the integration of Artificial Intelligence (AI) stands as a beacon of innovati…
Read articleAI in Mental Health: Assisting with Therapy and Diagnostics
In the realm of mental health, the integration of Artificial Intelligence (AI) stands as a beacon of hope and…
Read articleAI in Legal Compliance: Ensuring Regulatory Adherence
In an era where technology continually reshapes the boundaries of industries, Artificial Intelligence (AI) in…
Read article