Home / DevOps / Setup Jenkins on my Raspberry Pi 2

Setup Jenkins on my Raspberry Pi 2

Setup Jenkins on my Raspberry Pi 2

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.

Getting into the Raspbian Stretch Lite operating system via SSH
The default credentials to log into Raspberry Pi Stretch Lite is as follows:
Username: pi
Password: raspberry

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:

r.panev@Radoslavs-MacBook-Pro:~$ ssh pi@192.168.1.145
pi@192.168.1.145's password:
Linux raspberrypi 4.14.22-v7+ #1096 SMP Mon Feb 26 19:14:22 GMT 2018 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.
Last login: Fri Mar  2 16:03:44 2018 from 192.168.1.106

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:

uncomment this line
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 install oracle-java8-jdk -y

After the command had completed, I ran the following command:

pi@raspberrypi:~ $ java -version
java version "1.8.0_65"
Java(TM) SE Runtime Environment (build 1.8.0_65-b17)
Java HotSpot(TM) Client VM (build 25.65-b01, mixed mode)

Setup Jenkins

Once I had installed Java on my Raspbian Stretch Lite, I continued on to Setup 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 update -y && sudo apt 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:

pi@raspberrypi:~ $ systemctl status jenkins.service
● jenkins.service - LSB: Start Jenkins at boot time
   Loaded: loaded (/etc/init.d/jenkins; generated; vendor preset: enabled)
   Active: active (exited) since Fri 2018-03-02 16:57:36 EET; 14min ago
     Docs: man:systemd-sysv-generator(8)
  Process: 10066 ExecStop=/etc/init.d/jenkins stop (code=exited, status=0/SUCCESS)
  Process: 10109 ExecStart=/etc/init.d/jenkins start (code=exited, status=0/SUCCESS)

Mar 02 16:57:33 raspberrypi systemd[1]: Starting LSB: Start Jenkins at boot time...
Mar 02 16:57:34 raspberrypi jenkins[10109]: Correct java version found
Mar 02 16:57:34 raspberrypi su[10139]: Successful su for jenkins by root
Mar 02 16:57:34 raspberrypi su[10139]: + ??? root:jenkins
Mar 02 16:57:34 raspberrypi su[10139]: pam_unix(su:session): session opened for user jenkins by (uid=0)
Mar 02 16:57:36 raspberrypi jenkins[10109]: Starting Jenkins Automation Server: jenkins.
Mar 02 16:57:36 raspberrypi systemd[1]: Started LSB: Start Jenkins at boot time.

Once Jenkins was installed, I could access it with my browser via http://192.168.1.145:8080.

Unlocking Jenkins

sudo cat /var/lib/jenkins/secrets/initialAdminPassword

Setup Jenkins on my Raspberry Pi 2

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.
Setup Jenkins on my Raspberry Pi 2

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.

Setup Jenkins on my Raspberry Pi 2

That marked the end of the initial configurations for Jenkins. With that, I Jenkins showed me the home screen to create new jobs.

Setup Jenkins on my Raspberry Pi 2

Install Jenkins plugins

To install a plugin I use the following script – install_jenkins_plugin.sh
I execute the following command :

wget https://gist.githubusercontent.com/chuxau/6bc42f0f271704cd4e91/raw/87287e042c0981e4f62bf426058cd2d42fa02e9e/install_jenkins_plugin.sh && chmod +x install_jenkins_plugin.sh
sudo ./install_jenkins_plugin.sh ansible ssh ant ldap pam github workspace schedule pipeline owasp matrix gradle email

for more plugins click here!

exemplary output :

Installing: OWASP
Installing: Matrix
Installing: Gradle
Installing: Email
Check for missing dependecies ...
[/var/lib/jenkins/plugins/Build.hpi]
  End-of-central-directory signature not found.  Either this file is not
  a zipfile, or it constitutes one disk of a multi-part archive.  In the
  latter case the central directory and zipfile comment will be found on
  the last disk(s) of this archive.
[/var/lib/jenkins/plugins/Email.hpi]
  End-of-central-directory signature not found.  Either this file is not
  a zipfile, or it constitutes one disk of a multi-part archive.  In the
  latter case the central directory and zipfile comment will be found on
  the last disk(s) of this archive.
[/var/lib/jenkins/plugins/Gradle.hpi]
  End-of-central-directory signature not found.  Either this file is not
  a zipfile, or it constitutes one disk of a multi-part archive.  In the
  latter case the central directory and zipfile comment will be found on
  the last disk(s) of this archive.
[/var/lib/jenkins/plugins/Matrix.hpi]


then restart the Jenkins
sudo systemctl restart  jenkins

About panev

Вашият коментар

Вашият имейл адрес няма да бъде публикуван. Задължителните полета са отбелязани с *