Install Jenkins Server On Linux (Ubuntu 22.04)


Apr 07, 2025

Overview


  • This tutorial talks about how to install and run the Jenkins server and build up the connection between the server and the agents.
  • We use “Controller“ to indicate the Jenkins Server, and “Agent“ to indicate the controlled devices, such as RPI.

Execution


CREATE Jenkins SSH Credential

  • Enter the Jenkins server webpage
  • Go To "Dashboard" > "Manage Jenkins" > "Credentials"
  • Find the “Add credentials“ icon, it is hidden in “(global)” link and you need to extend it
  • Fill in the form
    • Kind: SSH Username with private key
    • ID: jenkins_ssh_key
    • Description: ssh key for jenkins agent
    • username: jenkins_agent (depends on RPI login username)
    • Private Key: select Enter directly and press the Add button to insert the content of your private key file at ~/.ssh/jenkins_agent_key
    • Passphrase: fill in your passphrase when generating the SSH key pair, leave it empty if it doesn’t
  • Press the Create button

COPY Credentials To Agent

  • To Be Added

CREATE Nodes

  • To Be Added

Installation


INSTALL JAVA And Set PATH $JAVA_HOME

  • Install Java / Amazon Corretto first
    # [Notes 1] Ensure JDK installation path should be corrected before set $JAVA_HOME path
    # If you installed on PC, the dir name usually shows "amd64" instead of "arm64"
    $ sudo update-alternatives --config java
    There is only one alternative in link group java (providing /usr/bin/java): /usr/lib/jvm/java-21-openjdk-amd64/bin/java
    Nothing to configure.
    

INSTALL ADD The Repository Key To Your System

# The default version of Jenkins in Ubuntu is often behind the latest available version.
# Ensure you get the latest fixes and features, use the project-maintained packages to install Jenkins.

# The gpg --dearmor command is used to convert the key into a format that apt recognizes.
# First, add the repository key to your system:
$ sudo wget -O /usr/share/keyrings/jenkins-keyring.asc \
https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key

# Next, let’s append the Debian package repository address to the server’s sources.list:
# The [signed-by=/usr/share/keyrings/jenkins.gpg] portion of the line ensures
# that apt will verify files in the repository using the GPG key that you just downloaded.
$ 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

# Run apt command to update the new repository
$ sudo apt update

# Install Jenkins
$ sudo apt install jenkins

AUTO-START Service When Boot

$ sudo systemctl enable jenkins

FIRST Access Jenkins Webpage

# Access the Jenkins Webpage
# https://[IP Address]:8080

# It will shows a dialog and ask for default admin password
$ Cat it from /var/jenkins_home/secrets/initialAdminPassword

INSTALL Recommended Plugins

  • When login the Jenkins webpage, install the recommended plugins

CREATE The First Admin User

# Username: jenkins
# Password: jenkins
# Full name: ******
# E-mail address: ******@gmail.com

SETUP Jenkins Account On Linux

# Jenkins will create its own account and group, both named "jenkins"
# We need to access via jenkins account and generate SSH key pair to build up connection between the controller and agent

# add password to jenkins account
$ sudo passwd jenkins
# I would like set password as "jenkins"

# switch user to jenkins
$ su jenkins

GENERATING SSH key pair

# Make sure it's in jenkins account
# We need a SSH key to pair the controller and the agents, here is how we generate the SSH key

# Generating the SSH key on the server side
# The default setting of ssh-keygen is RSA + 2048bit or 3072bit, but they are out-dated and denied, so it needs to add "-b 4096" argument
$ ssh-keygen -t rsa -b 4096
Generating public/private rsa key pair.
Enter file in which to save the key (/var/lib/jenkins/.ssh/id_rsa):
...
# Follow the steps, you may see theis message
...
SHA256:...
...
The key's randomart image is:
+---[RSA 4096]----+
...
+----[SHA256]-----+

# Ensure there are .ssh directory created and id_rsa and id_rsa.pub files inside
# cd .ssh/
# ls
id_rsa    id_rsa.pub

INSTALL And Configure CIFS

# Update to the latest
$ sudo apt update && sudo apt upgrade -y

# Install SAMBA
$ sudo apt install samba

# If you see installation failed messages like this:
The following packages have unmet dependencies:
 samba : Depends: python3-samba but it is not going to be installed
         Depends: samba-common-bin (= 2:4.15.13+dfsg-0ubuntu1.5) but it is not going to be installed
         Depends: libwbclient0 (= 2:4.15.13+dfsg-0ubuntu1.5) but 2:4.15.13+dfsg-0ubuntu1.6 is to be installed
         Depends: samba-libs (= 2:4.15.13+dfsg-0ubuntu1.5) but 2:4.15.13+dfsg-0ubuntu1.6 is to be installed
         Recommends: attr
         Recommends: python3-markdown but it is not going to be installed
         Recommends: samba-dsdb-modules but it is not going to be installed
         Recommends: samba-vfs-modules but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
# Try downgrade libwbclient0 packages to specific version may fixed this issue.
$ sudo apt install libwbclient0=2:4.15.13+dfsg-0ubuntu1.5

# If you have the issue above, try installation again when fix it
$ sudo apt install samba

# If SAMBA has installed success, using "whereis" command to check it
$ whereis samba
samba: /usr/sbin/samba /usr/lib/x86_64-linux-gnu/samba /etc/samba /usr/share/samba /usr/share/man/man8/samba.8.gz /usr/share/man/man7/samba.7.gz

# Setting up Samba
# Step 1
# create a directory for it to share:
$ mkdir /home/[username]/[share folder name]/
e.g.
$ mkdir /home/qaserver/JenkinsTestResults/
$ mkdir /home/qaserver/JenkinsData/

# Step 2
# Enter smb.conf
$ sudo vim /etc/samba/smb.conf

# Step 3
# Add the following lines at the bottom of the file:
# Please change "sambashare" to the share folder name
[sambashare]
    comment = Samba on Ubuntu
    path = /home/username/sambashare
    read only = no
    browsable = yes

e.g. 
[JenkinsTestResults]
    comment = Stored Jenkins test results under it, each test results will be separated by RPI name and created timestamp
    path = /home/username/JenkinsTestResults
    read only = no
    browsable = yes

[JenkinsData]
    comment = Stored materials for Jenkins testing
    path = /home/username/JenkinsData
    read only = no
    browsable = yes

# Step 4
# Enable & Restart SAMBA service
$ sudo service smbd enable
$ sudo service smbd restart

# Update the firewall rules to allow Samba traffic:
sudo ufw allow samba
# Verify the SAMBA has been added
$ sudo ufw app list
Available applications:
  CUPS
  OpenSSH
  Samba

# Step 5
# Setting up User Accounts and Connecting to Share, SAMBA doesn't use the system account and password
$ sudo smbpasswd -a [username]
e.g.
$ sudo smbpasswd -a jenkins
New SMB password: jenkins

FAQ


  • Using Known Hosts File Verification Strategy Failed
# We select "Known hosts file Verification Strategy" in "Host Key Verification Strategy" option
# The controller should access to agent at least once, and most of time, the "ssh-copy-id" will create known-host file in both side

# It shows error message like this when launching
...
Cannot found known hosts under /var/lib/jenkins/.ssh/known-hosts...
...

# If you saw error message like this, ensure the jenkins account made a SSH keygen and known hosts file under its $HOME directory
  • Solved SSH Access Allowed But Authentication Failed
...
... SSh access allowed ...
ERROR: Server rejected the 1 private key(s) for jenkins_agent (credentialId:SSH Key From Server Jenkins Account/method:publickey)
ERROR: Failed to authenticate as jenkins_agent with credential=SSH Key From Server Jenkins Account
...

# If you saw error message like above, it means SSH key doesn't acceptable, ensure the algortihm greater than RSA + 4096bit (default is 3072 or 2048)
# Re-generate a SSH key and copy to agent and try again

Reference


#jenkins #ubuntu #cifs #linux #samba






你可能感興趣的文章

Fetch 與 Promise (三):注意事項

Fetch 與 Promise (三):注意事項

# 第一次夜訪鹽巴,就失敗

# 第一次夜訪鹽巴,就失敗

[Note] JS: OOP - Introduction

[Note] JS: OOP - Introduction






留言討論