Jenkins is a Continuous Integration (CI) tool whose purpose is to automate repetitive phases of software development such as builds and unit tests to ensure continuous delivery of functional software.
The application is developed in Java and takes advantage of the latest potentials of this language to allow the extension of its functionalities by making use of plugins, which vary from statistics and execution reports to cluster management and distributed systems.
Also, the application has packages for several distributions, being Ubuntu, Debian, and RHEL-based distributions the ones that take the best advantage of it. Another alternative is to use Docker to deploy it on any server.
In this post, we will use the package that Jenkins distributes for Ubuntu 20.04.
Install Jenkins on Ubuntu 20.04
As mentioned above, Jenkins is developed in Java, so you need to install Java first. Then, add the Jenkins repository and use apt command to install Jenkin on your Ubuntu Linux Distribution..
Installation Steps,
1. Install Java
So, open a terminal or connect via SSH to the computer.
After that, update the system
sudo apt update sudo apt upgrade
Now proceed to install Java 11 from the official Ubuntu 20.04 repositories by running:
sudo apt install openjdk-11-jre openjdk-11-jdk
You can check the installation, showing the version that has been installed
java --version
2. Add the Jenkins repository
After Java, install the apt-transport-https
package needed for the Jenkins repository to be added correctly.
sudo apt install apt-transport-https
Now, download and add the GPG key from the repository.
wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -
Output:
OK
Now add the Jenkins repository by modifying the system software source file:
sudo nano /etc/apt/sources.list
And add, at the end of the file, the following line:
deb https://pkg.jenkins.io/debian-stable binary/
Save the changes and exit the text editor.
3. Install Jenkins
Now the repository is added, you just have to refresh APT and install Jenkins with this pair of commands
sudo apt update sudo apt install jenkins
Jenkins includes a system service that is automatically started and enabled by the system. You can check the status of the running service using systemctl command.
sudo systemctl status jenkins
Sample Output:
● jenkins.service - LSB: Start Jenkins at boot time Loaded: loaded (/etc/init.d/jenkins; generated) Active: active (exited) since Mon 2021-04-05 01:34:57 CEST; 44s ago Docs: man:systemd-sysv-generator(8) Tasks: 0 (limit: 2286) Memory: 0B CGroup: /system.slice/jenkins.service Apr 05 01:34:56 imaginelinux systemd[1]: Starting LSB: Start Jenkins at boot time... Apr 05 01:34:56 imaginelinux jenkins[5069]: Correct java version found Apr 05 01:34:56 imaginelinux jenkins[5069]: * Starting Jenkins Automation Server jenkins Apr 05 01:34:56 imaginelinux su[5118]: (to jenkins) root on none Apr 05 01:34:56 imaginelinux su[5118]: pam_unix(su-l:session): session opened for user jenkins by (uid=0) Apr 05 01:34:57 imaginelinux jenkins[5069]: ...done. Apr 05 01:34:57 imaginelinux systemd[1]: Started LSB: Start Jenkins at boot time.
Because Jenkins runs Out-the-box there is not much more to do except to get the initial admin user key with the command
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
Sample Output
bff56c4e8df243edaaa4361790bc5947
We have to copy this initial password because we will need it.
4. Complete the installation
By default, Jenkins works on TCP port 8080. You can change this in the Jenkins configuration file.
sudo nano /etc/default/jenkins
And locate the HTTP_PORT
section and assign the port you want and after closing the editor, restart Jenkins.
5. Start Jenkins
Now you can open your web browser and go to http://your-server:port
Replace your-server
and port
with the domain or IP address and port you have assigned to Jenkins.
You will see the initial screen where you will have to copy the password you have previously obtained.
Then, you can choose to install the suggested plugins or select the plugins you need.
Continue with the installer until you create the administrator user. You will then have to configure the installation, but you can leave the default settings.
At the end of the whole process, you will see the Jenkins dashboard indicating that it is ready to use.
Conclusion
Jenkins is one of the most important tools for DevOps and all sysadmins who need to automate tasks and deploy programs in production. On the other hand, Jenkins works well thanks to Java and for this reason, it has great support for Linux.