Jenkins is open source continuous integration tool that facilitates continuous aspects of continuous delivery.

Preamble:

Jenkins is an open source automation server used for continuous delivery and, ultimately, to accelerate the software delivery process and pipeline. It is built in Java and has more than 1000 plugins to support automation of virtually anything, so that humans can actually focus their time on things computers cannot do. In this tutorial we will learn how to deploy a Jenkins Server and start our task automation journey.

What to Use Jenkins for:

Use Jenkins to automate your development or task workflow so you can focus on work that matters most and leave the mundane and repetitive task for the Jenkins Server to execute. Jenkins is commonly used for:

  • Building projects
  • Running tests to detect bugs and other issues as soon as they are introduced
  • Running jobs or tasks on remote servers
  • Static code analysis
  • Continuous code deployment Execute repetitive tasks, save time, and optimize your development process with Jenkins.
  • Integration with numerous automation tools such as Ansible, Chef, Puppet …

Installing Jenkins Pre-requisites

Set up the hostname and update the system:

1
2
3
hostnamectl set-hostname jenkins.domain.com
yum update
yum upgrade

Install the required repository:

1
2
3
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
yum install https://downloads.ulyaoth.net/rpm/ulyaoth-latest.centos.x86_64.rpm

Install Jenkins repository:

1
2
wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo
rpm --import https://jenkins-ci.org/redhat/jenkins-ci.org.key

Install Vim text editor:

1
yum install vim

Create jenkins user with sudo Rights:

1
2
3
useradd jenkins
passwd jenkins
usermod -a -G wheel

alt text

Install OpenSSL:

1
2
yum install ulyaoth-openssl1.1.0
echo 'export PATH=/usr/local/ulyaoth/ssl/openssl1.1.0/bin:$PATH' >> /etc/profile

Installing Jenkins

Switch user to the Jenkins user and run all following commands using sudo:

1
2
3
su - jenkins
sudo yum install java-1.8.0-openjdk
sudo yum install jenkins

Configure the Firewall to allow port 8080 - (Optional):

1
2
firewall-cmd --zone=public --add-port=8080/tcp --permanent
firewall-cmd --reload

Start Jenkins service:

1
2
3
sudo systemctl enable jenkins
sudo systemctl start jenkins
sudo systemctl status jenkins

With your Browser: Go to http://your-ip-address:8080 Verify that Jenkins is running on port 8080

Installing and Configuring Nginx as Reverse Proxy

Installing Nginx web server:

1
2
3
4
yum install ulyaoth-nginx
systemctl enable nginx
systemctl start nginx
systemctl status nginx

Lets-Encrypt for Jenkins:

1
2
3
4
5
yum install letsencrypt
which letsencrypt
systemctl stop nginx
systemctl status nginx
/usr/bin/letsencrypt certonly --standalone

Create a Virtual Host: vim /etc/nginx/conf.d/jenkins.domain.com.conf

And paste in the following code snippet and adapt it to your environment

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
upstream jenkins {
server 127.0.0.1:8080 fail_timeout=0;
}
server {
listen 80;
listen [::]:80 ipv6only=on;
server_name jenkins.domain.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
listen [::]:443 ssl ipv6only=on;
server_name jenkins.domain.com;
ssl on;
ssl_certificate /etc/letsencrypt/live/jenkins.domain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/jenkins.domain.com/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/jenkins.domain.com/fullchain.pem;
ssl_protocols TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers "EECDH+AESGCM:EECDH+AES";
ssl_ecdh_curve secp384r1;
ssl_session_cache shared:SSL:10m;
ssl_session_tickets off;
ssl_session_timeout 1d;
ssl_stapling on;
ssl_stapling_verify on;
resolver 8.8.8.8 8.8.4.4 valid=300s;
resolver_timeout 5s;
add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; reload";
add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;
access_log /var/log/nginx/jenkins.access.log;
error_log /var/log/nginx/jenkins.error.log;
location / {
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_redirect http:// https://;
proxy_pass http://jenkins;
# Required for new HTTP-based CLI
proxy_http_version 1.1;
proxy_request_buffering off;
proxy_buffering off; # Required for HTTP-based CLI to work over SSL
# workaround for https://issues.jenkins-ci.org/browse/JENKINS-45651
add_header 'X-SSH-Endpoint' 'jenkins.domain.com:50022' always;
}
}

Configure Jenkins using the UI Wizard

Configuring Jenkins:

Go to the website and follow the prompt to finish configuring Jenkins UI

alt text Next, enter the default credential alt text Next, Install suggested plugins alt text Next, wait for the plugins to be installed alt text Next, create the admin user and password alt text

Setting Up Security in Jenkins:

  • On Configure Global Security page check Enable Security.
  • On Security Realm choose Jenkin’s own user database and make sure Allow users to sign up is checked.
  • On Authorization choose Logged-in users can do anything then click Save

More in Securing Jenkins: Securing Jenkins

How to reset Jenkins Admin password: Reset Admin Password

Jenkins documentation for more: Jenkins Documentation

General Conclusion:

This marks the end of our tutorial, Jenkins - An Open Source Automation Server, that enables system administrators to better automate mundane and repetitive tasks on large IT Infrastructure. Jenkins plays also an important role in the continuous integration and continuous deployment process. Don’t hesitate give it a try and you will discover the power of Jenkins.

Comments