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
CREATE Nodes
Installation
INSTALL JAVA And Set PATH $JAVA_HOME
INSTALL 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
$ 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
$ sudo apt update
$ sudo apt install jenkins
AUTO-START Service When Boot
$ sudo systemctl enable jenkins
FIRST Access Jenkins Webpage
$ 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
SETUP Jenkins Account On Linux
$ sudo passwd jenkins
$ su jenkins
GENERATING SSH key pair
$ 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):
...
...
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
$ sudo apt update && sudo apt upgrade -y
$ sudo apt install samba
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.
$ sudo apt install libwbclient0=2:4.15.13+dfsg-0ubuntu1.5
$ sudo apt install samba
$ 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
$ mkdir /home/[username]/[share folder name]/
e.g.
$ mkdir /home/qaserver/JenkinsTestResults/
$ mkdir /home/qaserver/JenkinsData/
$ sudo vim /etc/samba/smb.conf
[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
$ sudo service smbd enable
$ sudo service smbd restart
sudo ufw allow samba
$ sudo ufw app list
Available applications:
CUPS
OpenSSH
Samba
$ sudo smbpasswd -a [username]
e.g.
$ sudo smbpasswd -a jenkins
New SMB password: jenkins
FAQ
- Using Known Hosts File Verification Strategy Failed
...
Cannot found known hosts under /var/lib/jenkins/.ssh/known-hosts...
...
- 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
...
Reference
- How To Install Jenkins on Ubuntu 22.04
- Installing Jenkins On Linux
- Installing SAMBA On Linux