Install Jenkins on a Ubuntu server

Ticker

6/recent/ticker-posts

Install Jenkins on a Ubuntu server

Question : The DevOps team of xFusionCorp Industries is planning to setup some CI/CD pipelines. After several meetings they have decided to use Jenkins server. So, we need to setup a Jenkins Server as soon as possible so that we can start our testing. Please complete the task as per requirements mentioned below:

Install jenkins on jenkins server using apt only, and start its service.

Jenkin's admin user name should be theadmin, password should be Adm!n321, full name should be Anita and email should be anita@jenkins.com.

Note:

For this task ssh into jenkins server using user root and password S3curePass from jump host.

To complete the jenkins installation after installing packages and after starting the jenkins service, click on the + button in the top left corner and select option Select port to view on Host 1, enter port 8081 and click on Display Port.


Note: For these kind of scenarios requiring changes to be done in a web UI, please take screenshots so that you can share it with us for review in case your task is marked incomplete. You may also consider using a screen recording software such as loom.com to record and share your work.iew in case your task is marked incomplete. You may also consider using a 


This task is based on web UI, you can refer below Video Solution for better understanding 

Jenkins is a popular open source CI (Continuous Integration) tool which is widely used for project development, deployment, and automation.

This article will guide you through the process of installing Jenkins on a Ubuntu server 


Prerequisites : - 

Install JAVA packages.

Install & Configure Jenkins repo


Solution:  

1. Login on the jenkins server as a root 

thor@jump_host /$ ssh root@jenkins

The authenticity of host 'jenkins (172.16.238.19)' can't be established.

ECDSA key fingerprint is SHA256:pwMe1x4+HXU/9T18PAaeGwB4xYaelyxdnKIEDKyeBMk.

ECDSA key fingerprint is MD5:e3:a3:8a:fe:7a:04:4d:3c:27:dc:fb:04:c3:bc:94:22.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added 'jenkins,172.16.238.19' (ECDSA) to the list of known hosts.

root@jenkins's password:

Welcome to Ubuntu 16.04.6 LTS (GNU/Linux 4.15.0-101-generic x86_64)

  * Documentation:  https://help.ubuntu.com

 * Management:     https://landscape.canonical.com

 * Support:        https://ubuntu.com/advantage

 The programs included with the Ubuntu system are free software;

the exact distribution terms for each program are described in the

individual files in /usr/share/doc/*/copyright.

 Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by

applicable law.

 root@jenkins:~# 

2. Update the packages 

root@jenkins:~# apt-get update

Hit:1 http://archive.ubuntu.com/ubuntu xenial InRelease

Get:2 http://archive.ubuntu.com/ubuntu xenial-updates InRelease [109 kB]                            

Get:3 http://archive.ubuntu.com/ubuntu xenial-backports InRelease [107 kB]                                     

Get:4 http://security.ubuntu.com/ubuntu xenial-security InRelease [109 kB]        

Get:5 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 Packages [2559 kB]

Get:6 http://archive.ubuntu.com/ubuntu xenial-updates/restricted amd64 Packages [16.4 kB]  

Get:7 http://archive.ubuntu.com/ubuntu xenial-updates/universe amd64 Packages [1544 kB]

Get:8 http://archive.ubuntu.com/ubuntu xenial-updates/multiverse amd64 Packages [26.2 kB]

Get:9 http://archive.ubuntu.com/ubuntu xenial-backports/main amd64 Packages [10.9 kB]

Get:10 http://archive.ubuntu.com/ubuntu xenial-backports/universe amd64 Packages [12.7 kB]

Get:11 http://security.ubuntu.com/ubuntu xenial-security/main amd64 Packages [2051 kB]

Get:12 http://security.ubuntu.com/ubuntu xenial-security/restricted amd64 Packages [15.9 kB]

Get:13 http://security.ubuntu.com/ubuntu xenial-security/universe amd64 Packages [984 kB]

Get:14 http://security.ubuntu.com/ubuntu xenial-security/multiverse amd64 Packages [8820 B]

Fetched 7554 kB in 1s (5923 kB/s)                     

Reading package lists... Done

root@jenkins:~#


3. Download Jenkins repo and configure it

root@jenkins:~# wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | apt-key add -

OK

root@jenkins:~# sh -c 'echo deb https://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'

root@jenkins:~#

root@jenkins:~# ll /etc/apt/sources.list.d/

total 16

drwxr-xr-x 1 root root 4096 Jun 18 15:14 ./

drwxr-xr-x 1 root root 4096 Jun 18 15:14 ../

-rw-r--r-- 1 root root   49 Jun 18 15:14 jenkins.list

root@jenkins:~#


4. Install the packages 

root@jenkins:~# apt install apt-transport-https

Reading package lists... Done

Building dependency tree      

Reading state information... Done

The following additional packages will be installed:

  libasn1-8-heimdal libcurl3-gnutls libgmp10 libgnutls30 libgssapi3-heimdal libhcrypto4-heimdal libheimbase1-heimdal

  libheimntlm0-heimdal libhogweed4 libhx509-5-heimdal libkrb5-26-heimdal libldap-2.4-2 libnettle6 libp11-kit0

  libroken18-heimdal librtmp1 libsasl2-2 libsasl2-modules libsasl2-modules-db libtasn1-6 libwind0-heimdal

Suggested packages:

  gnutls-bin libsasl2-modules-otp libsasl2-modules-ldap libsasl2-modules-sql libsasl2-modules-gssapi-mit

  | libsasl2-modules-gssapi-heimdal

The following NEW packages will be installed:

  apt-transport-https libasn1-8-heimdal libcurl3-gnutls libgmp10 libgnutls30 libgssapi3-heimdal libhcrypto4-heimdal

  libheimbase1-heimdal libheimntlm0-heimdal libhogweed4 libhx509-5-heimdal libkrb5-26-heimdal libldap-2.4-2 libnettle6

  libp11-kit0 libroken18-heimdal librtmp1 libsasl2-2 libsasl2-modules libsasl2-modules-db libtasn1-6 libwind0-heimdal

0 upgraded, 22 newly installed, 0 to remove and 75 not upgraded.

Need to get 2506 kB of archives.

After this operation, 8029 kB of additional disk space will be used.

Do you want to continue? [Y/n] y 

Get:1 http://archive.ubuntu.com/ubuntu xenial/main amd64 libgmp10 amd64 2:6.1.0+dfsg-2 [240 kB]

Get:2 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 libnettle6 amd64 3.2-1ubuntu0.16.04.2 [93.7 kB]

Get:3 http://archive.ubuntu.com/ubuntu xenial-updates/mai

Setting up libsasl2-modules-db:amd64 (2.1.26.dfsg1-14ubuntu0.2) ...

Setting up libsasl2-2:amd64 (2.1.26.dfsg1-14ubuntu0.2) ...

Setting up libldap-2.4-2:amd64 (2.4.42+dfsg-2ubuntu3.13) ...

Setting up librtmp1:amd64 (2.4+20151223.gitfa8646d-1ubuntu0.1) ...

Setting up libcurl3-gnutls:amd64 (7.47.0-1ubuntu2.19) ...

Setting up apt-transport-https (1.2.35) ...

Setting up libsasl2-modules:amd64 (2.1.26.dfsg1-14ubuntu0.2) ...

Processing triggers for libc-bin (2.23-0ubuntu11) ...

root@jenkins:~#


4. Update the system packages 

root@jenkins:~# apt-get update

Hit:1 http://archive.ubuntu.com/ubuntu xenial InRelease

Hit:2 http://archive.ubuntu.com/ubuntu xenial-updates InRelease                                      

Hit:3 http://archive.ubuntu.com/ubuntu xenial-backports InRelease                                   

Ign:4 https://pkg.jenkins.io/debian-stable binary/ InRelease                                        

Get:5 https://pkg.jenkins.io/debian-stable binary/ Release [2044 B]           

Get:6 https://pkg.jenkins.io/debian-stable binary/ Release.gpg [833 B]          

Hit:7 http://security.ubuntu.com/ubuntu xenial-security InRelease                 

Get:8 https://pkg.jenkins.io/debian-stable binary/ Packages [22.8 kB]

Fetched 25.6 kB in 0s (55.6 kB/s)                         

Reading package lists... Done

root@jenkins:~#


5. Install Jenkins using apt 

root@jenkins:~# apt install jenkins

Reading package lists... Done

Building dependency tree      

Reading state information... Done

The following additional packages will be installed:

  daemon net-tools psmisc

The following NEW packages will be installed:

  daemon jenkins net-tools psmisc

0 upgraded, 4 newly installed, 0 to remove and 75 not upgraded.

Need to get 71.3 MB of archives.

After this operation, 75.5 MB of additional disk space will be used.

Do you want to continue? [Y/n] y

Get:1 http://archive.ubuntu.com/ubuntu xenial/main amd64 net-tools amd64 1.60-26ubuntu1 [175 kB]

Get:2 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 psmisc amd64 22.21-2.1ubuntu0.1 [48.1 kB]

Get:3 http://archive.ubuntu.com/ubuntu xenial/universe amd64 daemon amd64 0.6.4-1 [98.2 kB]

Get:4 https://pkg.jenkins.io/debian-stable binary/ jenkins 2.289.1 [71.0 MB]

Fetched 71.3 MB in 2s (32.7 MB/s)     

perl: warning: Setting locale failed.

perl: warning: Please check that your locale settings:

        LANGUAGE = (unset),

        LC_ALL = (unset),

        LC_CTYPE = "en_US.UTF-8",

        LANG = "en_US.UTF-8"

    are supported and installed on your system.

perl: warning: Falling back to the standard locale ("C").

debconf: delaying package configuration, since apt-utils is not installed

Selecting previously unselected package net-tools.

(Reading database ... 10938 files and directories currently installed.)

Preparing to unpack .../net-tools_1.60-26ubuntu1_amd64.deb ...

Unpacking net-tools (1.60-26ubuntu1) ...

Selecting previously unselected package psmisc.

Preparing to unpack .../psmisc_22.21-2.1ubuntu0.1_amd64.deb ...

Unpacking psmisc (22.21-2.1ubuntu0.1) ...

Selecting previously unselected package daemon.

Preparing to unpack .../daemon_0.6.4-1_amd64.deb ...

Unpacking daemon (0.6.4-1) ...

Selecting previously unselected package jenkins.

Preparing to unpack .../jenkins_2.289.1_all.deb ...

Unpacking jenkins (2.289.1) ...

Processing triggers for systemd (229-4ubuntu21.22) ...

Setting up net-tools (1.60-26ubuntu1) ...

Setting up psmisc (22.21-2.1ubuntu0.1) ...

Setting up daemon (0.6.4-1) ...

Setting up jenkins (2.289.1) ...

invoke-rc.d: could not determine current runlevel

invoke-rc.d: policy-rc.d denied execution of start.

Processing triggers for systemd (229-4ubuntu21.22) ...

root@jenkins:~# 


6. While starting Jenkins services you may get error for java.

root@jenkins:~# service jenkins start

ERROR: No Java executable found in current PATH: /bin:/usr/bin:/sbin:/usr/sbin

If you actually have java installed on the system make sure the executable is in the aforementioned path and that 'type -p java' returns the java executable path

root@jenkins:~#


7. Install Java package

root@jenkins:~# apt install openjdk-8-jdk

Reading package lists... Done

Building dependency tree      

Reading state information... Done

The following additional packages will be installed:

  ca-certificates-java dbus fontconfig fonts-dejavu-extra hicolor-icon-theme java-common libasound2 libasound2-data

  libasyncns0 libatk1.0-0 libatk1.0-data libavahi-client3 libavahi-common-data libavahi-common3 libcairo2 libcap-ng0

  libcups2 libdatrie1 libdbus-1-3 libdrm-amdgpu1 libdrm-common libdrm-intel1 libdrm-nouveau2 libdrm-radeon1 libdrm2 libelf1

  libflac8 libgdk-pixbuf2.0-0 libgdk-pixbuf2.0-common libgif7 libgl1-mesa-dri libgl1-mesa-glx libglapi-mesa libglib2.0-0

  libglib2.0-data libgraphite2-3 libgtk2.0-0 libgtk2.0-bin libgtk2.0-common libharfbuzz0b libice-dev libice6 liblcms2-2

  libllvm6.0 libnspr4 libnss3 libnss3-nssdb libogg0 libpango-1.0-0 libpangocairo-1.0-0 libpangoft2-1.0-0 libpciaccess0

  libpcsclite1 libpixman-1-0 libpthread-stubs0-dev libpulse0 libsensors4 libsm-dev libsm6 libsndfile1 libthai-data libthai0

  libtxc-dxtn-s2tc0 libvorbis0a libvorbisenc2 libx11-6 libx11-dev libx11-doc libx11-xcb1 libxau-dev libxcb-dri2-0

  libxcb-dri3-0 libxcb-glx0 libxcb-present0 libxcb-render0 libxcb-shm0 libxcb-sync1 libxcb1-dev libxcomposite1 libxcursor1

  libxdamage1 libxdmcp-dev libxfixes3 libxi6 libxinerama1 libxrandr2 libxrender1 libxshmfence1 libxt-dev libxt6 libxtst6

  libxxf86vm1 openjdk-8-jdk-headless openjdk-8-jre openjdk-8-jre-headless shared-mime-info x11-common x11proto-core-dev

  x11proto-input-dev x11proto-kb-dev xdg-user-dirs xorg-sgml-doctools xtrans-dev

Suggested packages:

  dbus-user-session | dbus-x11 default-jre libasound2-plugins alsa-utils cups-common librsvg2-common gvfs libice-doc

  liblcms2-utils pciutils pcscd pulseaudio lm-sensors libsm-doc libxcb-doc libxt-doc openjdk-8-demo openjdk-8-source

  visualvm icedtea-8-plugin libnss-mdns fonts-ipafont-gothic fonts-ipafont-mincho fonts-wqy-microhei fonts-wqy-zenhei

  fonts-indic

The following NEW packages will be installed:

  ca-certificates-java dbus fontconfig fonts-dejavu-extra hicolor-icon-theme java-common libasound2 libasound2-data

  libasyncns0 libatk1.0-0 libatk1.0-data libavahi-client3 libavahi-common-data libavahi-common3 libcairo2 libcap-ng0

  libcups2 libdatrie1 libdbus-1-3 libdrm-amdgpu1 libdrm-common libdrm-intel1 libdrm-nouveau2 libdrm-radeon1 libdrm2 libelf1

  libflac8 libgdk-pixbuf2.0-0 libgdk-pixbuf2.0-common libgif7 libgl1-mesa-dri libgl1-mesa-glx libglapi-mesa libglib2.0-0

  libglib2.0-data libgraphite2-3 libgtk2.0-0 libgtk2.0-bin libgtk2.0-common libharfbuzz0b libice-dev libice6 liblcms2-2

  libllvm6.0 libnspr4 libnss3 libnss3-nssdb libogg0 libpango-1.0-0 libpangocairo-1.0-0 libpangoft2-1.0-0 libpciaccess0

  libpcsclite1 libpixman-1-0 libpthread-stubs0-dev libpulse0 libsensors4 libsm-dev libsm6 libsndfile1 libthai-data libthai0

  libtxc-dxtn-s2tc0 libvorbis0a libvorbisenc2 libx11-dev libx11-doc libx11-xcb1 libxau-dev libxcb-dri2-0 libxcb-dri3-0

  libxcb-glx0 libxcb-present0 libxcb-render0 libxcb-shm0 libxcb-sync1 libxcb1-dev libxcomposite1 libxcursor1 libxdamage1

  libxdmcp-dev libxfixes3 libxi6 libxinerama1 libxrandr2 libxrender1 libxshmfence1 libxt-dev libxt6 libxtst6 libxxf86vm1

  openjdk-8-jdk openjdk-8-jdk-headless openjdk-8-jre openjdk-8-jre-headless shared-mime-info x11-common x11proto-core-dev

  x11proto-input-dev x11proto-kb-dev xdg-user-dirs xorg-sgml-doctools xtrans-dev

The following packages will be upgraded:

  libx11-6

1 upgraded, 103 newly installed, 0 to remove and 74 not upgraded.

Need to get 73.3 MB of archives.

After this operation, 408 MB of additional disk space will be used.

Do you want to continue? [Y/n] y

Setting up openjdk-8-jdk:amd64 (8u292-b10-0ubuntu1~16.04.1) ...

update-alternatives: using /usr/lib/jvm/java-8-openjdk-amd64/bin/appletviewer to provide /usr/bin/appletviewer (appletviewer) in auto mode

update-alternatives: using /usr/lib/jvm/java-8-openjdk-amd64/bin/jconsole to provide /usr/bin/jconsole (jconsole) in auto mode

Processing triggers for libc-bin (2.23-0ubuntu11) ...

Processing triggers for systemd (229-4ubuntu21.22) ...

Processing triggers for ca-certificates (20170717~16.04.2) ...

Updating certificates in /etc/ssl/certs...

0 added, 0 removed; done.

Running hooks in /etc/ca-certificates/update.d...

done.

done.

root@jenkins:~#


8. Start Jenkins services & check the status 

root@jenkins:~# service jenkins start

Correct java version found

 * Starting Jenkins Automation Server jenkins                                                                         [ OK ]

root@jenkins:~#

root@jenkins:~# service jenkins status

Correct java version found

Jenkins Automation Server is running with the pid 4350

root@jenkins:~#


9. Open WEB GUI and proceed with further installation (refer video attached)


10. To unlock jenkins use initial password store in file 

root@jenkins:~# cat /var/lib/jenkins/secrets/initialAdminPassword

72a3ced82b7e4343aeccc6600807b277

root@jenkins:~#


11 . Click on Finish & Confirm to complete the task successful

Happy Learning!!!!


Apart from this if you need more clarity,  I have made a  tutorial video on this , 

please go through and share your comments. Like and share the knowledge



Post a Comment

0 Comments

Latest Posts

KodeKloud Kubernetes Security CKS  Lab Challenge 4 |  Audit-policy | Install & configure falco utility | Inspect the API server audit logs and identify the user