First the question why? And that's a very good question. There are so many different tools for CI/CD. Why should I set up something of my own? Obviously because it's fun and you learn something new. But I also don't like to work with a black box. I want full control, change everything.
And why Jenkins and a Raspberry Pi? I don't want to spend a lot of money either, so no cloud. In my opinion, the Raspberry Pi is the best compromise between long-term availability and electricity costs. And it's just for fun, so if it goes down no one will care. Maybe I'm wrong, but I think Jenkins is the best open source automation server with low system resources. Perfect for a Raspberry Pi.
I won't go into much detail about each step. When I set up my server, I just wrote everything down and now summarize it briefly. I have obtained my information on:
As I was writing this, I realized that my full setup is too much for one post. So this is only the first part and there is more to come. If you find a mistake or something is unclear, please write a comment.
Setup the Raspberry Pi
I'm using a Raspberry Pi with Raspberry Pi OS Lite. After writing the operating system to the SD card, I create an empty file SSH in the root directory of the SD card. This will enable the SSH server so you can simply log in using SSH. No need to connect a keyboard or monitor. Just scan your network with nmap and then connect with the default username=pi and password=raspberry. You can also check your router to find the IP of your Raspberry Pi.
I run this
nmap 192.168.178.* -p 22 --open
to find the IP. Then I connect with
Now it's time to make your Pi just a little bit secure. We create a new user and add them to the sudo group.
sudo adduser axju sudo usermod -a -G adm,dialout,cdrom,sudo,audio,video,plugdev,games,users,input,netdev,gpio,i2c,spi axju
Reconnect and delete the default user pi
exit ssh firstname.lastname@example.org sudo deluser -remove-home pi
Maybe you have to kill pi's process
sudo pkill -u pi
Checkout this, if you want to make your Raspberry Pi even more secure.
Change hostname (optional)
There is no need to change the name, but I like it. You can use the IP address to connect to the server, but you can also use the hostname. So this should also work:
But I will change raspberrypi.local to jenkins.local. First open the /etc/hosts file and update the lines with your old hostname:
sudo nano /etc/hosts
from raspberrypi to jenkins. Next change the /etc/hostname
sudo echo "jenkins" | sudo tee /etc/hostname
And finally run
sudo hostname jenkins
Now you can connect with ssh email@example.com
This is really easy. First, update your system and install Java
sudo apt update sudo apt upgrade -y sudo apt install -y openjdk-11-jdk
To make sure it worked, check the version of java
Now add Jenkins source to your sources.list
wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add - sudo sh -c 'echo deb https://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
No errors until now, then install Jenkins
sudo apt update sudo apt install -y jenkins
Make sure that Jenkins is running
sudo systemctl status jenkins
That was all. After the installing the post-installation setup wizard begins. Fist unlock Jenkins. If you visited http://jenkins.local:8080 the first time, you have to enter a secret key. You will get it with
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
Now you can install some plugins. I uses the options Install suggested plugins and create a admin account. If you get stuck are interested in more information, check the documentation.
You see, install Jenkins is not that complicated. But for now, this is only a really simple setup. So what coming next? There is a lot of stuff to do. Fist you can improve the power of your server with some agents. The Raspberry Pi doesn't use a lot of electricity, but it doesn't have a lot of power either. On my final server, all operations were performed on the agents. This way the Pi won't sweat. I'm also running Jenkins behind a reverse proxy and enabled ssl.
Another big point is the different jobs for Jenkins. There are a lot of pipelines doing cool things. This blog is also deliver with Jenkins. I hope you find it all as exciting as I do. There will definitely be more to come.