There are two main versions of Jenkins:
- Weekly: Released every week.
- Long-term Support (LTS): Released every 12 weeks. The Jenkins team picks the most stable release from the last time an LTS was released, and designates that as the next LTS version.
For enterprise platforms, we want the most recent and stable version; therefore, we will install the latest LTS version, which is currently 2.138.1.
There are many ways to install Jenkins, listed as follows:
- It is distributed as a Web Application ARchive (WAR), or .war, file, which is simply a collection of resources that, together, constitute a web application. A WAR file is how web applications written in Java are distributed; any operating system that supports Java would be able to run the WAR file. You can download it from mirrors.jenkins.io/war-stable/latest/jenkins.war and run it directly with java -jar jenkins.war --httpPort=8765. It'll then be available on port 8765.
- As a Docker container, which you can download from hub.docker.com/r/jenkins/jenkins/.
- As a distribution-specific package—different operating systems also maintain their own Jenkins package in their repository. Jenkins packages from the most common systems, including Ubuntu/Debian, Red Hat/Fedora/CentOS, Windows, and macOS, are maintained by the Jenkins team.
Ideally, we would run our Jenkins server (and everything else for that matter) inside isolated Docker containers, however, that requires an understanding of containers and Docker, which will be overwhelming to learn alongside Jenkins. Therefore, in this chapter, we will use the Jenkins package provided by the APT repositories, and you can migrate to using Docker after reading Chapter 17, Migrating to Docker.
First, get the public key for the Jenkins repository and add it to APT; this allows APT to verify the authenticity of the package:
jenkins@ci:$ wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -
Next, we need to add the Jenkins repository to the list of repositories that APT will search for. This list is stored at /etc/apt/sources.list, as well as in files within the /etc/apt/sources.list.d/ directory. Therefore, run the following command, which will create a new jenkins.list file and store the repository address inside:
jenkins@ci:$ echo 'deb https://pkg.jenkins.io/debian-stable binary/' | sudo tee /etc/apt/sources.list.d/jenkins.list
Lastly, update our local package index and install Jenkins:
jenkins@ci:$ sudo apt update && sudo apt -y install jenkins
The installation will do several things, as follows:
- Download the WAR file and place it at /usr/share/jenkins
- Create a new user called jenkins which will run the service
- Set up Jenkins as a service/daemon that runs when the system first starts
- Create a /var/log/jenkins/jenkins.log file and direct all output from Jenkins to this file
You can check the status of the Jenkins service by running sudo systemctl status jenkins.service.
Jenkins runs as a service in the background. It utilizes the Jetty server (eclipse.org/jetty/) to provide a web interface for users to interact with. By default, this server will bind to port 8080.