DEV Community

Back2Basics
Back2Basics

Posted on

Installing Jekins

In this blog I will guide you on installing Jenkins on ubunutu machine.

Prerequisites

  • 256MB of RAM
  • 1 GB of Disk space (10GB recommended for running as Docker container) Download the jenkins keyring and store the file in "/usr/share/keyrings/jenkins-keyring.asc" file
sudo wget -O /usr/share/keyrings/jenkins-keyring.asc \
  https://pkg.jenkins.io/debian-stable/
jenkins.io-2023.key
Enter fullscreen mode Exit fullscreen mode

Option:

O - for redirect the downloaded content to the file
Check the content in the output file. It is a public key.

Image description

Now setup the package manager to with the keyring file. It act as the verification key to download from the jenkins package manager server. Store the package file in package manager /etc/sources.list.d/ for convention name it as jenkins.

echo "deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc]" \
  https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
  /etc/apt/sources.list.d/jenkins.list > /dev/null
Enter fullscreen mode Exit fullscreen mode

Try testing:

Image description

What is tee command refers to The tee command in Linux (and other Unix-like operating systems) is used to read from standard input and write to standard output and one or more files simultaneously. It allows you to capture the output of a command while also displaying it on the screen.
Example:

# it will display the output and store/append to the output.txt file
echo "Another line" | tee -a output.txt

# it can also store the output to multiple files
echo "Multiple files" | tee file1.txt file2.txt
Enter fullscreen mode Exit fullscreen mode

Options:

a - append
i - ignore interrupt signals ( complete the process even if Ctrl+C signaled).

Update the apt package manager to resolve dependencies are upto date. Then install jenkins, it will install from the apt package manager.

sudo apt-get update
sudo apt-get install jenkins -y
Enter fullscreen mode Exit fullscreen mode

Option:

y - to auto approve the process of installation no manual approval to continue.
Create jenkins user to run jenkins only by jenkins user.
It will crate the jenkins user and jenkins as primary group.

sudo adduser jenkins
Enter fullscreen mode Exit fullscreen mode

Check the status of the jenkins daemon

sudo systemctl status jenkins
Enter fullscreen mode Exit fullscreen mode

Image description

Troubleshooting Jenkins:

Check why it is not running.

journalctl -u jenkins.service
Enter fullscreen mode Exit fullscreen mode

You will find that jenkins depends on java runtime (Jre).

Mar 08 11:54:31 workernode01 jenkins[2122]: jenkins: failed to find a valid Java installation
Mar 08 11:54:31 workernode01 systemd[1]: jenkins.service: Main process exited, code=exited, status=1/FAILURE
  Subject: Unit process exited
Enter fullscreen mode Exit fullscreen mode

Update the apt package manager and install Java 17 version.

Caution:

Check the java version recommended in official docs

sudo apt update
sudo apt install fontconfig openjdk-17-jre -y
Enter fullscreen mode Exit fullscreen mode

Restart jenkins daemon

systemctl restart jenkins
# or else below
# systemctl start jenkins 
Enter fullscreen mode Exit fullscreen mode

Check the Jenkins daemon status

sudo systemctl status jenkins

Now everything is configured properly. Now to work on jenkins check the

sh journalctl -xu jenkins

Mar 08 12:05:33 workernode01 jenkins[4694]: Please use the following password to proceed to installation:
Mar 08 12:05:33 workernode01 jenkins[4694]: c8a8ff85a01346449a9a83bd01299812
Mar 08 12:05:33 workernode01 jenkins[4694]: This may also be found at: /var/lib/jenkins/secrets/initialAdminPassword
Enter fullscreen mode Exit fullscreen mode

Jenkins Default port is 8080

Image description

Get the ip of the host and with the http::8080 jenkins controller dashboard will be accessed. If running localhost try with ip as localhost.

Image description

Get the Administator password form the file found in journalctl logs for jenkins /var/lib/jenkins/secrets/initialAdminPassword

cat /var/lib/jenkins/secrets/initialAdminPassword
Enter fullscreen mode Exit fullscreen mode

Copy and past in the jenkins webpage.

Note:

This is inital password and need to reset the password for this later. Continue you find the page below

Image description

Initially go with the suggested installation with suggested plugins. It will install the Git, ssh, emailer, etc bunch of pluging and required to run jenkins pipelines at very basic to moderate jobs.

Image description

Fill the form remember it is asking for the admin details.

Image description

Image description

Save and continue.

The Jenkins URL is used to provide the root URL for absolute links to various Jenkins resources. That means this value is required for proper operation of many Jenkins features including email notifications, PR status updates, and the BUILD_URL environment variable provided to build steps.
The proposed default value shown is not saved yet and is generated from the current request, if possible. The best practice is to set this value to the URL that users are expected to use. This will avoid confusion when sharing or viewing links.
Enter fullscreen mode Exit fullscreen mode

Now you can start using jenkins

Image description

Finally This is the admin jenkins dashboard. We can start working on this for creating Jenkins project/ adding nodes installing plugins etc.

Image description

Under manage jenkins -> System

Image description

-- Executors: number of vcpus. We can assign less than or equal to baremetal/vm cpus
-- Labels: We can assign multiple labels with space seperated to the nodes/agent.
-- Jenkins URL: this is the url you want to provide access to main jenkins controller dashboard. Here we are giving the http://:. We can provide a DNS url mapping to the IP and binding SSL certs to give https access.

Backup Jenkins Configuration

There were times when jenkins hosted machine was down due to system failures. To take the backup of main jenkins configuration /va/lib/jenkins/ directory.

tar -cvf backup-jenkins.tar /va/lib/jenkins/ 
Enter fullscreen mode Exit fullscreen mode

send a copy of the tar file in safe machine

rsync -aurvx backup-jenkins.ta <user-name>:<ip-addr>://<path-to-store-backup>
Enter fullscreen mode Exit fullscreen mode

Image description

Image description

Top comments (0)