Translate

Friday, March 2, 2018

A personal CI system


In this article I'm describing how to set up and configure a basic CI (Continuos Integration) system that can be used for many  things, based on an open source program called Jenkins.
Of course, for my projects to set up a CI  to build them is just little bit overshooting, but surely is interesting and fun.

Why I did it ?
To learn, exercise some sane DevOps habits, to have fun.

What we need ?
Well, a server, a github account, some applications and some time.
Specifically we need to have Java installed on the machine we'll use a CI server (Jenkins is in Java), a LAMP and some applications like building tools.

The goal is to set up a system that monitor a project in github, and depending some conditions, compile it automatically (if possible).
A condition can be updating the code on github, another could be a daily compile.
The idea is to have the code constantly compiled and maybe tested somehow, automatically.
In case of problems the developer (me) is notified.

OF COURSE this kind of system make sense for big projects where more developers are involved.
For a single developer on a small code like for for the MSP430 or Raspberri Pi doesn't make sense, but is fun, and is a good occasion to learn new things.

The CI system


On my server I decided to install Jenkins as base for my CI system.
I already save my projects on github, so Jenkins can simply connect to it, download the latest version of the code and compile it.
But Jenkins can also be used to execute maintenance jobs, checking for example on some server process.
In other words a system like Jenkins is extremely flexible, allowing to build complex tasks.
Each Jenkins job can call compilers, builders (like make or gradle), moving files, executing scripts or creating "pipelines", special scripts for Jenkins allowing to perform complex tasks.

Installation


It is quite easy and straightforward to install the system.
We need to have Java (1.7 and latest version), Jenkins and Gradle for future projects.
For the first experiment Gradle is not necessary.

Java

After a general update to the system (I'm currently using Ubuntu 16.04 LTS) I installed the latest version of java.

sudo apt-get install java

The apt-get installed the 1.8 version.

$ java -version
openjdk version "1.8.0_91"
OpenJDK Runtime Environment (build 1.8.0_91-8u91-b14-0ubuntu4~16.04.1-b14)
OpenJDK 64-Bit Server VM (build 25.91-b14, mixed mode)

Jenkins


After that I simply added a repository to apt-get, update and installed Jenkins.

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-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
sudo apt-get update
sudo apt-get install jenkins

The installation procedure takes care of many details, like creating a user (jenkins) attached to the application, setting directories, etc. so it is always a good thing to be able to use this procedure.
It is possible to do that manually but it requires really a lot of work.

Usually in this way it is installed the latest LTS version of Jenkins.
I wanted the latest one, so after the installation I looked for the file jenkins.war and found it in  /usr/share/jenkins.
I simply downloaded manually the latest jenkins.war file from the Jenkins website  and substituted to the one in /usr/share/jenkins.
Voila' ! Latest Jenkins installed !
(Update, using the same procedure just download the latest version).

Initial Configuration

Once Jenkins is installed is necessary to start it and configure it.
To do so, open a terminal on the server and locate where the file jenkins.war was installed.
For example :

find / -name jenkins.war 2>/dev/null

In my case was in /usr/share/jenkins.
Go to that directory and digit : java -jar jenkins.war --httpPort=

port is the port number to be used. Better to don't use the port 80. Typical value is 8080.

Note that on the terminal will be displayed an admin password to use the first time you connect to Jenkins, in order to configure it.

At this point, from any PC on the network simply open a browser and go to :

server_address:port_assigned

For example : 192.168.1.100:8080

On that browser, after copying the admin password from the terminal, will be possible to configure Jenkins, following the on screen instructions.

Other articles will cover specific settings of Jenkins for specific jobs.

Is possible to change some default parameters editing as root (sudo) the file /etc/default/jenkins

No comments:

Post a Comment