Skip to main content

CI/CD with Jenkins

Installing Jenkins

Install jenkins by following the instructions specific to your operating system of choice - Installing Jenkins.

We can use bellow commands to install Jenkins in RHEL 9 system:

dnf install -y wget java-17-openjdk
wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key
dnf install -y jenkins

Then we can use systemd to start the jenkins service:

service jenkins start

Running jenkins in docker

Pull the LTS Jenkins image:

docker pull jenkins/jenkins:lts

Run jenkins:

docker run --detach --publish 8080:8080 --volume jenkins_home:/var/jenkins_home --name jenkins jenkins/jenkins:lts

Print the initial admin password:

docker exec jenkins cat /var/jenkins_home/secrets/initialAdminPassword

Go to http://localhost:8080, provide the above admin password. Next step, we may select install suggested plugins.

Alternatively, we could share an existing JENKINS_HOME data directory with the container.

export JENKINS_HOME=/workspaces/jenkins_home
docker run -d --rm -p 8080:8080 -v $JENKINS_HOME:/var/lib/jenkins -e JENKINS_HOME=/var/lib/jenkins jenkins/jenkins:lts

Jenkins CLI tool

When the Jenkins server is running, the CLI tool can be downloaded from: $JENKINS_URL/jnlpJars/jenkins-cli.jar.

wget http://localhost:8080/jnlpJars/jenkins-cli.jar
chmod +x jenkins-cli.jar

Backup and restore Jenkins data

See https://www.jenkins.io/doc/book/system-administration/backing-up/