Deployment Jenkins for CI/CD Pipeline on Ubuntu 18.04

Didiet Agus Pambudiono
GITS Apps Insight
Published in
4 min readJul 22, 2019

--

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:

  1. Cloud VPS with specification: HDD 100GB, RAM 4GB, and 2 vCPUs
  2. Ubuntu server 18.04
  3. 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).

  1. Install Java Runtime Environment and Java Developer Kit
    sudo apt install openjdk-11-jdk openjdk-11-jre
  2. 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)
  3. Add the Jenkins repository key to the system
    wget -q -O — https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -
  4. 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’
  5. Run update for apt
    sudo apt update
  6. 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.

  1. Set Jenkins to start
    sudo systemctl start jenkins
  2. 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.
  3. 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.
Unlock Jenkins Page
  • 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.
Customize Jenkins Page
  • In the next page, we can create first Admin user.
Create First Admin User Page
  • We can configure the URL for Jenkins’ access in the next page.
Instance Configuration Page
  • When the Jenkins setup is complete, we can choose Start using Jenkins.
Jenkins is Ready Page

Jenkins’ dashboard:

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.

--

--