Deployment Jenkins for CI/CD Pipeline on Ubuntu 18.04
Come a day when GITS Indonesia had to migrate our existing CI/CD pipeline to a new server. Well, then we started using Jenkins.
Why Use Jenkins?
Jenkins is a self-contained, open source automation server which can be used to automate all sorts of tasks related to building, testing, and delivering or deploying software.
With Jenkins, we can accelerate software development through automation. Jenkins integrates development life cycle process; including build, document, test, package, stage, deploy, and much more.
Preparation and Requirement
For the deployment, we use:
- Cloud VPS with specification: HDD 100GB, RAM 4GB, and 2 vCPUs
- Ubuntu server 18.04
- Java Runtime Environment and Java Developer Kit.
Deployment on Ubuntu Server
Before we can use Jenkins, we need some dependencies and we need to install Jenkins to the server. We use Ubuntu server because this operating system is widely used and has support from both the user community and the company. And for the deployment of Jenkins, we use GCE (Google Cloud Engine).
- Install Java Runtime Environment and Java Developer Kit
sudo apt install openjdk-11-jdk openjdk-11-jre
- Check Java version
java -version
The output:openjdk version “11.0.3” 2019–04–16
OpenJDK Runtime Environment (build 11.0.3+7-Ubuntu-1ubuntu218.04.1)
OpenJDK 64-Bit Server VM (build 11.0.3+7-Ubuntu-1ubuntu218.04.1, mixed mode, sharing) - Add the Jenkins repository key to the system
wget -q -O — https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -
- Append the Debian package repository address to the servers’ sources list:
sudo sh -c ‘echo deb https://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list’
- Run update for apt
sudo apt update
- Install Jenkins
sudo apt install jenkins
Starting Jenkins
After the installation has been done, we have to make sure that Jenkins can run. We also have to make sure that every time the server is rebooting, the Jenkins can start the service automatically. Therefore, we need some steps to do.
- Set Jenkins to start
sudo systemctl start jenkins
- Check Jenkins status
sudo systemctl status jenkins
If everything went well, the beginning of the output should show that the service is active:● jenkins.service — LSB: Start Jenkins at boot time
Loaded: loaded (/etc/init.d/jenkins; generated)
Active: active (exited) since Mon 2019–07–22 02:47:39 UTC; 11min ago
Docs: man:systemd-sysv-generator(8)
Tasks: 0 (limit: 4915)
CGroup: /system.slice/jenkins.service
Jul 22 02:47:38 jenkins2 systemd[1]: Starting LSB: Start Jenkins at boot time…
Jul 22 02:47:38 jenkins2 jenkins[10308]: Correct java version found
Jul 22 02:47:38 jenkins2 jenkins[10308]: * Starting Jenkins Automation Server jenkins
Jul 22 02:47:38 jenkins2 su[10362]: Successful su for jenkins by root
Jul 22 02:47:38 jenkins2 su[10362]: + ??? root:jenkins
Jul 22 02:47:38 jenkins2 su[10362]: pam_unix(su:session): session opened for user jenkins by (uid=0)
Jul 22 02:47:38 jenkins2 su[10362]: pam_unix(su:session): session closed for user jenkins
Jul 22 02:47:39 jenkins2 jenkins[10308]: …done.
Jul 22 02:47:39 jenkins2 systemd[1]: Started LSB: Start Jenkins at boot time. - Set the Jenkins service to be available at boot
sudo systemctl enable jenkins
Setting Up Jenkins
After the Jenkins’ service start, we need to do some configuration for Jenkins. For example, we need to set Admin user and Jenkins URL.
- To set up the installation, visit Jenkins default port (8080), using the server domain name or IP address: http://jenkins-server-ip-or-domain:8080
You will see the Unlock Jenkins page, which displays the location of the initial password.
- In the Windows terminal, use cat command to display the password.
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
- At the next screen, you can choose Install suggested plugins.
- In the next page, we can create first Admin user.
- We can configure the URL for Jenkins’ access in the next page.
- When the Jenkins setup is complete, we can choose Start using Jenkins.
Jenkins’ dashboard:
After this configuration has been set up, we can use Jenkins for CI/CD Pipeline for our works.
Note:
If you use openSUSE Leap, you can read my another article on Medium:
https://medium.com/@sitidy/instalasi-jenkins-pada-opensuse-leap-15-0-3097506bd5d4
Didiet A. Pambudiono is a Cloud explorer, FOSS enthusiast and contributor, also DevOps engineer at GITS Indonesia.