We can easily install Jenkins using tradition package managers like Yum /Apt . But it is recommended to use configuration management tools like Salt , Chef or Puppet for better management. In this article, let me get you through steps to install Jenkins on CentOS /RedHat using Salt .
Salt can be used for data-driven orchestration, remote execution for any infrastructure, configuration management for any app stack, and much more. Learn more about salt from here >>
Step 1: Install Java for Jenkins using Salt
Note that Jenkins need Java runtime Environment to run it’s service. The version of Java to be installed depends on the version of Jenkins as mentioned below
- Jenkins 2.54 and newer: Java 8
- Jenkins 1.612 and newer: Java 7
You can find list of available Jenkins packages for CentOS /RedHat at http://pkg.jenkins-ci.org/redhat-stable/. We will install latest version 2.150.3-1.1 of Jenkins(at the time of this writing this article), so we need Java 8 as per the requirements. Java 8 runtime Environment is available as package java-1.8.0-openjdk for CentOS /RedHat . Let’s install the same using Salt state. If you are not familiar with Salt state, learn about from here >>.
Create file jenkins_installation.sls in the salt state directory and add below content.
java-install: pkg.installed: - pkgs: - java-1.8.0-openjdk
And don’t forget to add this state in your top.sls file.
base: 'jenkins-hostname.pvt': - jenkins_installation
Here jenkins-hostname.pvt is the hostname(minion ID) of the machine where you want to install Jenkins.
Step 2: Use Jenkins Formula
Now salt state for Java installation is ready. Let’s setup salt state for Jenkins. Fortunately we have salt formula available for Jenkins. Salt formula is a ready-made salt state written for a purpose.
Let’s use the Jenkins salt formula. Log in to salt master box and clone git repository of Jenkins formula to an appropriate location. As I have salt states in /srv directory, I will create a directory formulas inside the same directory and clone the public repo there.
mkdir /srv/formulas git clone https://github.com/saltstack-formulas/jenkins-formula.git
We need to inform Salt master to use the new Jenkins formula, for that open salt master configuration file /etc/salt/master and add the path of the Jenkins formula as file_roots .
file_roots: base: - /srv/salt
file_roots: base: - /srv/salt - /srv/formulas/jenkins-formula
Once done, restart the salt master.
sudo /etc/init.d/salt-master restart
Now open jenkins_installation.sls and add declaration to use Jenkins formula.
java-install: pkg.installed: - pkgs: - java-1.8.0-openjdk include: - jenkins
This will install latest package of Jenkins with default configuration, we don’t want this. We need to configure Jenkins as per our requirements and install a specific version. We can achieve this with Salt Pillar. If you are not familiar with Salt Pillar, learn about it here >>
Step 3: Configure Jenkins using Salt Pillar
Now go to the pillar directory and create jenkins.sls with below content.
jenkins: lookup: stable: True jenkins_port: 8080 home: /var/jenkins user: jenkins group: jenkins master_url: http://0.0.0.0:8080 pkgs: - jenkins: 2.150.3-1.1
Let me explain what these pillars do:
stable: True => Install Stable version of Jenkins.
jenkins_port: 8080 => Make Jenkins run on 8080 port.
home: /var/jenkins => Jenkins Home directory(where all Jenkins data is stored) can be set here.
user: jenkins group: jenkins => Jenkins service will run as mentioned user/group.
pkgs: – jenkins: 2.150.3-1.1 => Install specific version of Jenkins.
Step 4: Run salt highstate
Now you have everything ready. Let’s run salt highstate, which runs salt state on the Jenkins box along with every other boxes where salt minion is installed.
sudo salt '*' state.apply
Note : With the official salt formula for Jenkins, if you change Jenkins user from default user jenkins, the Jenkins service won’t start due to permission issue. I have raised a pull request with the Fix. Until they merge the pull request, you may use the forked repo in my Github account if you have plan to change the Jenkins user from default.
Hurray, you have completed the course. Congratulations 🙂
Thanks for the time taken to read my blog. Subscribe to this blog so that you don’t miss out anything useful (Checkout Right Sidebar for the Subscription Form) . Please also put your thoughts on this article as comments .