How to Install Jenkins Self Hosted on Ubuntu 20.04. In this post we will explain what Jenkins server is with its features and then we will proceed to installations guide.
What is Jenkins Server?
Jenkins is a free, open-source automation tool written in Java that helps in the building, testing, deploying and monitoring of software projects. It is compatible with operating systems like Windows, macOS and integrates various deployment technologies on cloud or can use a Docker container in it. The tool supports 1500+ plugins and other features that aid in the Continuous Integration and continuous delivery (CI/CD) process.
Most companies prefer Jenkins over other DevOps tools as it helps accelerate the software development process and delivers quick results. It is a flexible, easy to install and has configuration automation tool that helps developers and operational teams to collaborate and enable smooth functioning. Developers can track repeated tasks, discover and fix errors at at an early stage so it is easy to debug.
It is flexible in creating the jobs and supports different types of source code repositories like SVN or Git. Jenkins server runs an active and thriving community for customer queries and other support services.
In this post, we will show you how to install Jenkins Self Hosted on Ubuntu 20.04.
Before starting, you will need to install the Java and other required dependencies to your server. You can install all of them by running the following command:
Next part of the guide of how to install Jenkins Self Hosted on Ubuntu 20.04 we recommend configuring Nginx as a reverse proxy for Jenkins. So you can access it through the port 80.
First, install the Nginx package by running the following command:
apt-get install nginx -y
Once the Nginx package is installed, create an Nginx virtual host configuration file using the following command:
nano /etc/nginx/conf.d/jenkins.conf
Add the following lines:
upstream jenkins {
keepalive 32; # keepalive connections
server 127.0.0.1:8080; # jenkins ip and port
}
# Required for Jenkins websocket agents
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 80; # Listen on port 80 for IPv4 requests
server_name jenkins.example.com; # replace 'jenkins.example.com' with your server domain name
# this is the jenkins web root directory
# (mentioned in the /etc/default/jenkins file)
root /var/run/jenkins/war/;
access_log /var/log/nginx/jenkins.access.log;
error_log /var/log/nginx/jenkins.error.log;
# pass through headers from Jenkins that Nginx considers invalid
ignore_invalid_headers off;
location ~ "^/static/[0-9a-fA-F]{8}\/(.*)$" {
# rewrite all static files into requests to the root
# E.g /static/12345678/css/something.css will become /css/something.css
rewrite "^/static/[0-9a-fA-F]{8}\/(.*)" /$1 last;
}
location /userContent {
# have nginx handle all the static requests to userContent folder
# note : This is the $JENKINS_HOME dir
root /var/lib/jenkins/;
if (!-f $request_filename){
# this file does not exist, might be a directory or a /**view** url
rewrite (.*) /$1 last;
break;
}
sendfile on;
}
location / {
sendfile off;
proxy_pass http://jenkins;
proxy_redirect default;
proxy_http_version 1.1;
# Required for Jenkins websocket agents
proxy_set_header Connection $connection_upgrade;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Host $host;
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_max_temp_file_size 0;
#this is the maximum upload size
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffering off;
proxy_request_buffering off; # Required for HTTP CLI commands
proxy_set_header Connection ""; # Clear for keepalive
}
}
Save and close the file then verify the Nginx for any configuration error using the following command:
nginx -t
If everything is fine, you will get the following output:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Finally, restart the Nginx service to apply the changes:
systemctl restart nginx
You can also check the status of the Nginx using the following command:
systemctl status nginx
You will get the following output:
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2022-02-12 06:27:47 UTC; 4s ago
Docs: man:nginx(8)
Process: 7373 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 7374 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Main PID: 7375 (nginx)
Tasks: 2 (limit: 2341)
Memory: 2.5M
CPU: 45ms
CGroup: /system.slice/nginx.service
├─7375 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
└─7376 nginx: worker process
Feb 12 06:27:47 ubuntu2004 systemd[1]: Starting A high performance web server and a reverse proxy server...
Feb 12 06:27:47 ubuntu2004 systemd[1]: nginx.service: Failed to parse PID from file /run/nginx.pid: Invalid argument
Feb 12 06:27:47 ubuntu2004 systemd[1]: Started A high performance web server and a reverse proxy server.
In order to Jenkins work with Nginx you need to make Jenkins to listen on localhost. You can do it by editing the Jenkins configuration file:
At this point of our guide of how to install Jenkins Self Hosted on Ubuntu 20.04, the Nginx is installed and configured as a reverse proxy for Jenkins. You can now access the Jenkins web interface using the URL http://jenkins.example.com. You should see the Jenkins initial password screen:
Now, open your terminal and run the following command to fetch the Jenkins password:
cat /var/lib/jenkins/secrets/initialAdminPassword
You will get the Jenkins password in the following output:
148309c551cf4718a3cb051b80e25452
Copy and paste the above password to the web installation screen and click on the Continue button. You should see the Customize Jenkins screen:
How to Install Jenkins Self Hosted on Ubuntu 20.04 Conclusion
In the above post, we explained how to install Jenkins on Ubuntu 20.04. We also explained how to configure Nginx as a reverse proxy for Jenkins. You can now start creating your first project using the Jenkins dashboard.
I am a fan of open source technology and have more than 10 years of experience working with Linux and Open Source technologies. I am one of the Linux technical writers for Cloud Infrastructure Services.
00votes
Article Rating
Subscribe
Login and comment with
I allow to create an account
When you login first time using a Social Login button, we collect your account public profile information shared by Social Login provider, based on your privacy settings. We also get your email address to automatically create an account for you in our website. Once your account is created, you'll be logged-in to this account.
DisagreeAgree
Login and comment with
I allow to create an account
When you login first time using a Social Login button, we collect your account public profile information shared by Social Login provider, based on your privacy settings. We also get your email address to automatically create an account for you in our website. Once your account is created, you'll be logged-in to this account.