How I setup Jenkins on my Raspberry Pi 3 with Raspbian Stretch Lite
Jenkins is a renowned open source automation server that can help offload programmers from performing repetitive tasks like:
- running unit tests to make sure new code does not break existing codes.
- compiling and packaging the binaries from codes and dependencies.
- deploying new binaries to testing servers.
- checking whether production server is up and running.
- and etc.
If you have a Raspberry Pi 3 and you want to automate some of the tasks for your side projects, you may want to consider setting up Jenkins on your Raspberry Pi 3 with Raspbian Stretch Lite as the operating system.
This post documents how I setup Jenkins on my Raspberry Pi 3 with Raspbian Stretch Lite.
My hardware list for this setup
I used the following hardware for my Jenkins server:
- Raspberry PI 3 Model B A1.2GHz 64-bit quad-core ARMv8 CPU, 1GB RAM
- Official Raspberry Pi 3 Case - Red/White
- Kingston Digital 32GB microSDHC Class 10 UHS-I 45R Flash Card (SDC10G2/32GBSP)
- Unused USB charger
- AmazonBasics RJ45 Cat-6 Ethernet Patch Cable - 3 Feet (0.9 Meters)
Hardware needed for installing Raspbian Stretch Lite onto the microSD
The Raspberry Pi 3 will load Raspbian Stretch Lite from the microSD. As such, we will need to have a SD card reader to perform the installation of Raspbian Stretch Lite onto the microSD card.
Since my computer has an in-built SD card reader, I was able to proceed with installing Raspbian Stretch Lite onto my microSD card.
Downloading Raspbian Stretch Lite for my Raspberry Pi 3
After making sure that I had the all the necessary hardware, I continued on to download a version of the Raspbian Stretch Lite operating system for my Raspberry Pi 3.
Compared to the desktop version, Raspberry Stretch Lite does not include the graphical desktop environment. Since Jenkins does not require a graphical desktop environment, using Raspbian Stretch Lite as the operating system for my Raspberry Pi 3 is a more efficient option.
With that, I went over to the Raspbian download page to download a copy of Raspbian Stretch Lite. As of this writing, the one that was available was dated 29th November 2017:
I clicked on the Download Zip button for Raspbian Stretch Lite and saved the zip file onto my file system.
Installing Raspbian Stretch Lite onto my microSD card
Once my browser had completed the download for the
.zip file, I extracted the
.img file from the
.zip file. The
.img file was the operating system image that I used for installing Raspbian Stretch Lite onto my microSD card.
If you are using a windows machine, you can use Win32DiskImager to install the operating system for your Raspberry Pi 3.
If you are using a Linux desktop, you should be able to Etcher to install the operating system for your Raspberry Pi 3.
Enabling SSH server on Raspbian Stretch Lite first boot
With an SSH server running on Raspbian Stretch Lite, I do not have to find a spare keyboard and monitor in order to configure Raspbian Stretch Lite after it had booted up for the first time. To ensure that I had the SSH server running after the first boot, I created a file named "ssh” in the boot partition of the microSD card:
Assembling the hardware for the Raspberry Pi LEMP Server
Next, I removed my microSD card from my SD card reader and inserted it to the microSD card slot on the Raspberry Pi 3 board. After that, I went ahead to assemble the Raspberry Pi 3 board to the Official Raspberry Pi case.
Starting the Raspbian Stretch Lite operating system
With the assembly of my Raspberry Pi 3 board and Official Raspberry Pi case, I connected one end of the RJ45 cable to the RJ45 port on my Raspberry Pi 3 board and the other end of the cable to one of the switch port of my home router. After that, I connected my micro USB cable and supply power to my Raspberry Pi 3 board.
Finding the IP address of my Raspberry Pi 3
When Raspbian Stretch Lite boots up, it requested an IP address from my router. This IP address was needed for me to SSH into my Raspberry Pi 3. I went to my router's address allocation table and find an entry with the name raspberrypi. In my case, the router allocated 192.168.1.109 to my Raspbian Stretch Lite.
Getting into the Raspbian Stretch Lite operating system via SSH
The default credentials to log into Raspberry Pi Stretch Lite is as follows:
With the default credentials and the IP address that my router had given to my Raspbian Stretch Lite, I then used SSH to get into the operating system:
I then entered raspberry when my Raspbian Stretch Lite prompted for password. With that, my Raspbian Stretch Lite greeted me with the following output:
Linux raspberrypi 4.9.59-v7+ #1047 SMP Sun Oct 29 12:19:23 GMT 2017 armv7l The programs included with the Debian GNU/Linux system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. SSH is enabled and the default password for the 'pi' user has not been changed. This is a security risk - please login as the 'pi' user and type 'passwd' to set a new password.
Changing the default password
Since Raspbian Stretch Lite suggested that using the default password for the 'pi' user is a security risk, the next thing that I did was to change the default password. To do so, I entered the following command:
For the three prompts that followed the command, I entered raspberry and my favourite password twice.
Configuring the locale settings
The next thing that I did was to configure the locale settings for my Raspbian Stretch Lite. To do so, I first opened up the Raspberry Pi Software Configuration Tool:
I then followed through the following screens to generate the "en_US.UTF-8" locale and set it as the default locale for the system environment:
After doing so, I opened up
/etc/default/locale with nano:
sudo nano /etc/default/locale
And updated the contents to look like the following:
LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 LANGUAGE=en_US.UTF-8
This would ensure that the locale settings for my Jenkins server persist through system reboots.
The default timezone of Raspbian Stretch Lite is "Etc/UTC". However, since my Raspberry Pi 3 will be residing in Singapore, I wanted it to follow Singapore's Timezone.
To change the timezone on my Raspbian Stretch Lite, I used the Raspberry Pi Software Configuration Tool mentioned earlier and went through the following steps:
Once I had configured the Timezone, I entered the following command to restart Raspbian Stretch Lite:
sudo shutdown -r now
I then got back into Raspbian Stretch Lite with the following command once it had restarted successfully:
Preventing Hash Sum mismatch errors
By default, this installation of Raspbian Stretch Lite will attempt to download packages from a mirror that is nearest to my location. However, the download processes for some of the packages threw Hash Sum mismatch errors. To prevent such errors from occurring, I configured apt-get to always download packages from archive.raspbian.org. To do so, I changed the contents of the
/etc/apt/sources.list file to look like the following:
#deb http://mirrordirector.raspbian.org/raspbian/ stretch main contrib non-free rpi # Uncomment line below then 'apt-get update' to enable 'apt-get source' #deb-src http://archive.raspbian.org/raspbian/ stretch main contrib non-free rpi deb http://archive.raspbian.org/raspbian/ stretch main contrib non-free rpi
Installing Java on my Raspbian Stretch Lite
Jenkins is written in Java. As such, I will need to get Java installed on my Raspbian Stretch Lite. To install the faster Java version on Raspbian Stretch Lite, I entered the following command:
sudo apt-get install oracle-java8-jdk -y
After the command had completed, I ran the following command:
and got the following output as an indication that Java 8 was installed successfully:
Java(TM) SE Runtime Environment (build 1.8.0_65-b17) Java HotSpot(TM) Client VM (build 25.65-b01, mixed mode)
Once I had installed Java on my Raspbian Stretch Lite, I continued on to install Jenkins. To do so, I entered the following command:
wget -q -O - https://jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add - sudo sh -c 'echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list' sudo apt-get update sudo apt-get install jenkins -y
Once the command had completed, I ran the following command:
systemctl status jenkins.service
and got the following output as an indication that Jenkins was installed successfully:
● jenkins.service - LSB: Start Jenkins at boot time Loaded: loaded (/etc/init.d/jenkins; generated; vendor preset: enabled) Active: active (exited) since Wed 2017-12-27 22:14:45 +08; 4min 40s ago Docs: man:systemd-sysv-generator(8) Dec 27 22:14:43 raspberrypi systemd: Starting LSB: Start Jenkins at boot time... Dec 27 22:14:43 raspberrypi jenkins: Correct java version found Dec 27 22:14:43 raspberrypi su: Successful su for jenkins by root Dec 27 22:14:43 raspberrypi su: + ??? root:jenkins Dec 27 22:14:43 raspberrypi su: pam_unix(su:session): session opened for user jenkins by (uid=0) Dec 27 22:14:45 raspberrypi jenkins: Starting Jenkins Automation Server: jenkins. Dec 27 22:14:45 raspberrypi systemd: Started LSB: Start Jenkins at boot time.
Once Jenkins was installed, I could access it with my browser via
The Jenkins that I had installed showed the following screen when I accessed it for the first time:
Following the instructions, I got the initial admin password for Jenkins on my terminal screen with the following command:
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
and supplied it to the text field on the Unlock Jenkins page. I then clicked on the Continue button to proceed with the initial configurations of Jenkins.
Going through Jenkins initial configurations
Once Jenkins is unlocked, I then followed through some initial configurations screens.
Firstly, I clicked on Skip Plugin Installations button at the screen that notified that my Jenkins instance was offline.
In the Create First Admin User page, I supplied the first admin user credentials and clicked on the Save and Finish button.
After the first admin user was created, I clicked on the Start Using Jenkins button to start using Jenkins.
That marked the end of the initial configurations for Jenkins. With that, I Jenkins showed me the home screen to create new jobs.
Buying the hardware to build your Jenkins server on a Raspberry Pi 3
If you do not have the Raspberry Pi 3 hardware mentioned in this post yet, you may want to purchase them from Amazon. Simply click on the button below to add the Raspberry Pi 3 hardware to your cart. You may remove anything that you already have or replace some of the hardware with other hardware.