In my last article, I explained the principles behind CI/CD, in this one we get to learn about a specific implementation (Jenkins) and how to install it both locally and on a cloud hosted server. I hope you learn as much as I did!
- What is Jenkins?
- How do I install Jenkins locally (Mac)?
- How do I install Jenkins on a cloud-based linux/unix server?
- Now that I have Jenkins installed, how do I set it up?
What is Jenkins?
Jenkins is an Open-Source CI/CD tool written in Java which provides automation tools used to build and deliver software. It’s a server-based application that requires a web server like Apache Tomcat to execute.
This tool is free and widely used with over 300,000 installations (probably a lot more since I got this number), growing in popularity every day. It became so popular because of it’s monitoring of repeated tasks which arise during the development of projects without manual intervention.
Jenkins is a fork from another project called Hudson after a dispute with oracle. If you want to read about the dispute, it’s fairly interesting – check it out here.
If your team is developing a project, Jenkins will continuously test your builds and show you the errors in early stages of development saving development time (which costs money).
Code is built and tested as soon as the developer commits code. Jenkins will build and test the code many times a day – it can even test and build after each commit or specific times in the day.
Code is built immediately after any of the developers commits a change in an automated build process. It will then run automated tests, upon Successful (green) builds, Jenkins will deploy the source code into the test server and notify the deployment team. On build failures (red), Jenkins will notify the team of the errors immediately so they can be resolved and retested.
Why should we use Jenkins with our Continuous Integration pipeline?
Jenkins is being managed by the community which is open to the public. Every month, the Jenkins team hold public meetings and take inputs from the community to discuss changes.
As the landscape of technology grows, so does Jenkins. Currently there are over 1,500 plugins published to the Jenkins plugin database which make it more powerful and feature rich.
Jenkins also supports cloud-based architecture so that you can deploy Jenkins in cloud based platforms.
What are the alternatives to Jenkins?
- Drone CI (CD platform written in GoLang)
- TeamCity (JetBrains)
How do I install Jenkins locally (Mac)?
To learn you can play locally but it’s better to learn in a real world environment, in any case – here is how to install Jenkins locally:
This guide is specifically for mac users, if you haven’t already installed homebrew – I recommend it to install Jenkins. Alternatively you can download it directly from https://www.jenkins.io/download/ if you are running a different OS.
Here are some simple commands:
- Install the latest Weekly version:
brew install jenkins
- Install a specific Weekly version:
brew install [email protected]_VERSION
- Start the Jenkins service:
brew services start jenkins
- Restart the Jenkins service:
brew services restart jenkins
- Update the Jenkins version:
brew upgrade jenkins
How do I access my local version of Jenkins?
After it’s installed just run
jenkins in your terminal and it will open up https://localhost:8080/login?from=2F
To get your password for Jenkins, run the following command to copy it to your clipboard:
pbcopy < /Users/InsertYourUserNameHere/.jenkins/secrets/initialAdminPassword
Paste in your password.
Follow the instructions for how to set up Jenkins in the section below titled “Setting up Jenkins“.
How do I install Jenkins on a cloud-based linux/unix server?
Where do I install Jenkins?
For production use you will want to install Jenkins on a linux/unix based server you will first need Java installed as a prerequisite.
We will be creating a cloud-based jenkins installation over on Digital Ocean – while it’s not free you can use this link: https://m.do.co/c/98ed549bfab5 to get a $100, 60 day free credit to use on their servers.
It will ask you to provide credit card details, you will be billed $5 hold on your account which should clear out within a few days. Check your email, there should be a new one with a credit linking you to https://www.digitalocean.com/billing which should show a $100 credit. Please note that this credit will expire after 60 days if it’s not used.
The account will have 60-days or until the $100 credit is used up. My recommendation is to stop what you are doing and create a calendar alert to remind you in 58 days from now to cancel.
Ok, I have a Digital Ocean account, now what?
Create your account and then confirm your subscription via email.
On the welcome screen fill out the details like you see below:
Click the blue start button at the bottom.
At the top right select “Create” and from the dropdown select “Droplets”.
On the next page select Ubuntu, Standard plan.
Select your datacenter for the country you are located in – for me I’m selecting New York. Head down to create a root password and fill it out with something you will remember or save it in your password manager. Bear in mind if the password isn’t secure enough you wont be able to create the droplet
If you lose your password or the one you have doesn’t work you can navigate to “droplets” on the left menu bar and then select “Access” and then reset root password which will email you a password reset.
Next, select 1 droplet, provide it a name “linux-jenkins”
Create the Droplet.
How do I access the command line on the server I created?
After the droplet is created, you will want to open the console.
A window will pop up requesting your login (username) which is root. Provide your password. You may be prompted to reset it.
Alternatively, you can use the IP and SSH in using:
ssh [email protected] (obviously your IP won’t be the same as mine) then type
yes ⏎ and provide your root password.
How do I install Jenkins on Digital ocean?
In order to run Jenkins, which is written java, you’ll need to first install Java.
In which ever terminal you chose from above, run
apt-get update (good practice) and then
sudo apt-get install default-jre then
java --version it should look like this:
[email protected]:~# java --version openjdk 11.0.7 2020-04-14 OpenJDK Runtime Environment (build 11.0.7+10-post-Ubuntu-2ubuntu218.04) OpenJDK 64-Bit Server VM (build 11.0.7+10-post-Ubuntu-2ubuntu218.04, mixed mode, sharing)
We are going to install the Debian package repository of Jenkins to automate installation and upgrade. First, we need to add the key to your system by running:
wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -
You should see
Then add the following entry in your /etc/apt/sources.list by running:
nano /etc/apt/sources.list and then add:
deb https://pkg.jenkins.io/debian-stable binary/ to the list. Press
x to close and save.
Lastly, update your package index and install Jenkins. Make sure you are in the root directory & Run
apt-get update to avoid errors. Then:
sudo apt install jenkins (You may be prompted for confirmation, just type
Now we need to verify Jenkins is running on our machine by running:
systemctl status jenkins
[email protected]:~# systemctl status jenkins ● jenkins.service - LSB: Start Jenkins at boot time Loaded: loaded (/etc/init.d/jenkins; generated) Active: active (exited) since Thu 2020-07-09 01:09:56 UTC; 7min ago Docs: man:systemd-sysv-generator(8) Tasks: 0 (limit: 4704) CGroup: /system.slice/jenkins.service Jul 09 01:09:55 linux-jenkins systemd: Starting LSB: Start Jenkins at boot ti Jul 09 01:09:55 linux-jenkins jenkins: Correct java version found Jul 09 01:09:55 linux-jenkins jenkins: * Starting Jenkins Automation Ser Jul 09 01:09:55 linux-jenkins su: Successful su for jenkins by root Jul 09 01:09:55 linux-jenkins su: + ??? root:jenkins Jul 09 01:09:55 linux-jenkins su: pam_unix(su:session): session opened fo Jul 09 01:09:55 linux-jenkins su: pam_unix(su:session): session closed fo Jul 09 01:09:56 linux-jenkins jenkins: ...done. Jul 09 01:09:56 linux-jenkins systemd: Started LSB: Start Jenkins at boot tim lines 1-16/16 (END)
You have now installed Jenkins! 🙌
By the way – You can type
q to exit the above readout.
How do I access Jenkins?
ip addr show and look for the
inet line and copy the IP.
In your browser, navigate to
http://188.8.131.52:8080 (obviously your IP will be different but the port
:8080 will be the same).
You should be prompted for your password in the browser. Just run
cat /var/lib/jenkins/secrets/initialAdminPassword and your password should appear below it. Copy paste that into the password field.
Now that I have Jenkins installed, how do I set it up?
Click on the “Install suggested plugins” option on the following screen. It will install all the plugins. The plugins install is really quick on the cloud based solution but doing it locally will entirely depend on your download speed and I recommend trying it in the cloud section above anyways.
You should now be prompted to create a username, password, name, and email address for the first admin user of the Jenkins install. Fill it out and click “Save and Continue”.
You will be prompted by a page telling you how to access it (you already know though 😉 ), click continue then on the following page click “Start using Jenkins”.
You will now see the default Jenkins UI.
If you’d like to stop Jenkins on the cloud, you can run
systemctl stop jenkins and to start it again run
systemctl start jenkins.
I hope you enjoyed this “brief” article introducing you to Jenkins and I look forward to writing more. In my next article on Jenkins, we will dive into setting up Jenkins for a CI/CD pipeline.
If you found this article helpful, give me a shout on twitter – I’d love to hear from you. @codingwithdrewk or connect with me on linkedin. As always, if you found any errors, just highlight it and mash that “R” button on the right side of the screen and I’ll get those fixed right up!
Featured Image Created by Ksenia Nenasheva Source: https://www.jenkins.io/images/logos/plumber/plumber.png
Leave a Reply