Jenkins CI/CD 01 Installation
Setup Jenkins CI/CD step by step
Create Your Own Automated Deployment Service with Jenkins
Jenkins is a Java-based CI/CD system tool that we are exploring in this tutorial,
following our previous introduction to Drone
If you plan to use Docker for installation and require Docker commands within Jenkins, you’ll need to address Docker-in-Docker issues.
For those less familiar with Docker and operating systems, it is recommended to follow the method described below, installing Jenkins directly on your host machine.
Below, we’ll go through the step-by-step installation process as per the official installation documentation
First, ensure that you have Java installed:
java -version
sudo apt install openjdk-11-jre
Next, install the Jenkins service on your host machine, opting for the stable version (LTS - Long Term Support):
curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo tee \
/usr/share/keyrings/jenkins-keyring.asc > /dev/null
echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
/etc/apt/sources.list.d/jenkins.list > /dev/null
sudo apt-get update
sudo apt-get install jenkins
Start the Jenkins service using the following command, and then access it via your web browser at localhost:8080
.
You’ll be prompted to enter the initial admin password:
sudo systemctl enable --now jenkins
Retrieve the initial admin password using the following command:
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
Plugin Installation
By default, Jenkins does not support pipelines, so you’ll need to install a pipeline plugin.
In this tutorial, we’re using Blue Ocean
.
To use Docker as an agent in your build process, you’ll also need to install two additional extensions:
- Docker plugin
- Docker Pipeline
You can search for and install these plugins in the Jenkins plugin management section:
Additionally, ensure that Docker is properly installed on your Jenkins host machine.
Docker Command Permissions
To configure Docker command permissions, first switch to the Jenkins user:
sudo su jenkins
Then, execute any Docker command, e.g., docker ps
.
If you encounter a permission denied message like:
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post
Avoid running sudo chmod 777 /var/run/docker.sock
.
The correct approach is to add the Jenkins user to the Docker user group:
cat /etc/passwd # List all users
sudo groupadd docker # Create a Docker user group (usually created when Docker is installed)
sudo usermod -aG docker jenkins # Add the Jenkins user to the Docker group
Restart the Jenkins service. You can trigger the restart by entering the following URL in your web browser:
http://jenlins_url/restart
Click the restart button, and once it’s back up, it will load the new configuration.
Now you can run Docker commands as the Jenkins user.