How to install and create pipelines in Jenkins
Last updated: November 10th 2022
Introduction
Jenkins is an open-source tool written in Java to set up continuous integration and continuous deployment (CICD) pipelines for faster software delivery. It is the main part of software development life cycle automation. This guide describes the step-by-step procedure of installing Jenkins and creating pipelines in Jenkins.
Prerequisites
- Webdock cloud Ubuntu instance (18.04 or later)
- You have shell (SSH) access to your VPS
Jenkins installation
First update the apt packages on ubuntu
$ sudo apt-get update -y
Install openjdk
$ sudo apt-get install default-jdk
Setup Jenkins' stable repository using following command
$ curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo tee /usr/share/keyrings/jenkins-keyring.asc > /dev/null $ echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] https://pkg.jenkins.io/debian-stable binary/ | sudo tee /etc/apt/sources.list.d/jenkins.list > /dev/null
Update the apt packages
$ sudo apt-get update -y
Install Jenkins using the following command
$ sudo apt-get install jenkins -y
After installation, enable and start Jenkins service.
$ sudo systemctl enable jenkins $ sudo systemctl start jenkins
Check the status of Jenkins service
$ sudo systemctl status jenkins
In case of our Webdock perfect server stacks, open port 8080
$ sudo ufw allow 8080
Set Up Jenkins
After installing Jenkins, access the server on port 8080 of the Webdock instance like http://www.example.com:8080
Jenkins will ask for an administrator password to unlock it. Get the administrator password from the Webdock instance using following command.
$ sudo cat /var/lib/jenkins/secrets/initialAdminPassword
Next it will ask for plugins installation. You can install plugins of your own choice or click on install suggested plugins button to install mostly used plugins.
After successful installation of plugins, it will take you to create the admin user for Jenkins.
After creating the admin user, Jenkins is properly configured and is ready to use.
Types of Jenkins pipelines
Freestyle project
Freestyle projects can be configured from Jenkins GUI by adding steps. It provides a lot of flexibility but it is much more difficult to write complex pipelines using the freestyle project. Using freestyle project you can
- Execute windows batch commands
- Invoke gradle script
- Execute shell commands
- Run workflow with timeout
Post build actions can also be added to the freestyle project using GUI. The post build action includes
- Archive the artifacts
- Build other project
- Send email notification
- Delete workspace after build is completed
- Aggregate downstream test results
- Publish JUnit test result report
Scripted pipeline
Scripted Pipeline was the first version of pipeline as a code in Jenkins. It was designed as a general-purpose DSL (Domain Specific Language) built with Groovy syntax. Jenkinsfile in the scripted pipeline is written on the Jenkins UI.
Scripted pipelines have only two types of basic blocks i.e, node and stage block. A node block specifies the machine that executes a particular pipeline and stage block can be a single stage or multiple as the task goes.
Declarative pipeline
Declarative Pipeline is a modern and more simplified way of writing Jenkinsfile. Declarative Pipeline is also written in a groovy syntax. In the declarative Pipeline, Jenkinsfile is stored and checked into a source control management system like git. On run time, the Jenkinsfile from git repo is cloned and executed.
Adding credentials to Jenkins
To enable Jenkins to interact with many third party applications like servers on cloud or github, credentials are added in Jenkins. Jenkins uses these credentials to connect with third party services. In order to add credentials to Jenkins, follow these steps.
Install credentials plugin
Before adding credentials, first install credentials plugin in Jenkins. The credentials plugin allows the user to store credentials in Jenkins.
While setting up the Jenkins, if you have installed suggested plugins, then this plugin is already installed. Otherwise click on Manage Jenkins from Jenkins dashboard
From the Manage Jenkins dashboard, click on the Manage Plugins
From the Plugin Manager, go to the Available tab.
Search for the Credentials Plugin plugin from the available plugins and install it.
If you do not see any Credentials Plugin plugin in the available tab, check it in the installed tab. If this plugin exists in the installed tab then it is already installed.
Add credentials
After installing the Credentials plugin, now click on the Manage Credentials under the Security section from Manage Jenkins dashboard.
Under Stores scoped to Jenkins, click on the Jenkins.
Click on the global credentials (unrestricted).
From the left side panel, click on the Add Credentials button.
Now it will ask for different attributes of the credentials you want to store. Following types of credentials can be added to Jenkins.
- Username with password
- Github app
- SSH username with private key
- Secret file
- Secret text
- Certificates
In order to add a simple username with password, add the details as follows
After adding details of credential, click on the OK button and it will add the credentials.
Writing CICD pipeline in Jenkins
In order to create a CICD pipeline in Jenkins, click on the New Item from the left side panel in Jenkins dashboard
Add the name of pipeline and select Pipeline as the type of pipeline.
It will take you to the configuration page of the pipeline. Scroll down to the Pipeline section and add the following script to the pipeline.
pipeline { agent any stages { stage('clone repo') { steps { script { sh ''' echo "clone github repo" ''' } } } stage('build project') { steps { script { sh ''' echo "building the project" ''' } } } stage('run tests') { steps { script { sh ''' echo "running automated test suite" ''' } } } stage('deploy application') { steps { script { sh ''' echo "deploy the application to server" ''' } } } } }
This pipeline script has multiple stages to deploy the application to the server. After writing the pipeline script, save the pipeline. Now from the pipeline, click on the Build now button to trigger the pipeline manually.
After the pipeline runs, it will show the status of the pipeline on Jenkins UI as follows.
Conclusion
Jenkins is the mostly used tool to build CI/CD pipelines for software delivery. This guide briefly describes the installation process of Jenkins and then writing the first CICD pipeline in Jenkins.
Related articles
-
How to install OpenLiteSpeed on Webdock
In this article we show you how you can install the OpenLiteSpeed web server on Ubuntu Jammy.
Last updated: March 29th 2023
-
How to Deploy your First Node.js Application on your Ubuntu Web Server
Deploy a Node.js application on your Ubuntu server and how to issue SSL certificates for your Node application.
Last updated: July 19th 2023
-
How to set up WireGuard on your Webdock Server
This article details how you can quickly and easily install WireGuard on your Webdock Server.
Last updated: July 21st 2024
-
How to set up OpenVPN on your Webdock Server
This article details how you can quickly and easily set up a VPN on your Webdock server.
Last updated: November 10th 2022
-
How to Install and configure aaPanel on Ubuntu
Install aaPanel on Ubuntu as well as building a LEMP stack, pointing your domain to your server and setting SSL certificates with Let's Encrypt.
Last updated: November 10th 2022
-
How to install azuracast on Webdock
This guide shows you how to work around certain issues when installing azuracast on Webdock.
Last updated: November 10th 2022
-
How to set up Runcloud on Webdock
This article details the steps you need to go through in order to install Runcloud on a Webdock server.
Last updated: July 29th 2024
-
How to set up cPanel on Webdock
This article details the steps you need to go through in order to install cPanel on a Webdock server.
Last updated: September 23rd 2024
-
How to set up Gridpane on Webdock
This article details the steps you need to go through in order to install Gridpane on a Webdock server.
Last updated: November 10th 2022
-
How to set up Ploi on Webdock
This article details the steps you need to go through in order to install Ploi on a Webdock server.
Last updated: November 10th 2022
-
How to set up Laravel Forge on Webdock
This article details the steps you need to go through in order to install Laravel Forge on a Webdock server.
Last updated: November 10th 2022
-
How to set up Plesk on Webdock
This article details the steps you need to go through in order to install Plesk on a Webdock server.
Last updated: November 10th 2022
-
How to set up Cyberpanel on Webdock
This article details the steps you need to go through in order to install Cyberpanel on a Webdock server.
Last updated: December 9th 2023
-
How to set up SpinupWP on Webdock
This article details the steps you need to go through in order to installSpinupWP on a Webdock server.
Last updated: March 15th 2023
-
How to set up DirectAdmin on Webdock
This article details the steps you need to go through in order to install DirectAdmin on a Webdock server.
Last updated: September 1st 2023
-
How to set up Hestia on Webdock
This article details the steps you need to go through in order to install Hestia on a Webdock server.
Last updated: November 10th 2022
-
How to set up Virtualmin on Webdock
This article details the steps you need to go through in order to install Virtualmin on a Webdock server.
Last updated: November 10th 2022
-
Basic WordPress site setup with aaPanel
In this guide, we will install and setup a basic WordPress site with aaPanel.
Last updated: January 23rd 2023
-
How to use Nginx as reverse proxy and secure connections with SSL certificates
Using Nginx to proxy pass your site with SSL security.
Last updated: July 19th 2023
-
Setting up monitoring with Netdata on your Webdock server
Setting up monitoring on your server to receive alerts and to know real-time resource consumption on your server.
Last updated: July 19th 2023
-
How to Setup Python Web Application With Flask Gunicorn and Nginx
A simple Python Flask web app hosting with Gunicorn and Nginx
Last updated: July 19th 2023
-
How to Daemonize an Application with Systemd
Using systemd to autostart your application on system startup.
Last updated: July 19th 2023
-
Set-up New Relic Monitoring on Your Webdock Server
This guide provides step-by-step instructions to install New Relic to monitor your VPS.
Last updated: July 29th 2024
-
Getting Started with Ruby on Rails on Webdock
In this guide, we will show you how to get started with Ruby on Rails on your Webdock server
Last updated: July 19th 2023
-
How to Install VaultWarden on Your Webdock Server
This guide provided step-by-step instructions to Vaultwarden, an open-source Password Manager on your Webdock Server.
Last updated: July 19th 2023
-
How to Install the Latest Version of HTOP on Ubuntu Server
Instructions to install latest htop package on your Ubuntu server
Last updated: July 29th 2024
-
How to Install ImageMagick 7 on Ubuntu LEMP/LAMP stacks
Simple instructions to install ImageMagick 7 along with the PHP extension
Last updated: November 1st 2023
-
A Quick Guide to Installing Rust on Ubuntu
Instructions to install Rust
Last updated: December 18th 2023
-
How To Install Proxmox on Your Webdock Server
This article provides instructions on how to install Proxmox on your Webdock server
Last updated: July 29th 2024
-
How To Run Nextcloud on Your Webdock Ubuntu Server
Instructions to Install Nextcloud on your server with Docker
Last updated: February 13th 2024
-
The Ultimate Guide to Setting Up Mastodon server
A detailed guide with instructions to set up Mastodon on your Webdock server
Last updated: February 20th 2024
-
A Guide To Setting Up Mindustry Game Server on Ubuntu
Step-by-step instructions to set up your own Mindustry server
Last updated: November 4th 2024
-
A Guide to Installing ERPNext on Your Webdock Server
Step-by-step instructions to install ERPNext - a resource planning software - on your server
Last updated: May 28th 2024
-
A Beginner's Guide to Installing Apache Kafka on Ubuntu
Detailed instructions to get Kakfa running on Ubuntu!
Last updated: June 20th 2024
-
A Quick Guide To Installing Rocket Chat on Ubuntu
Instructions to install Rocket Chat on your Ubuntu server
Last updated: July 2nd 2024
-
How to Install Ghost CMS on a Webdock Server
Easily install Ghost CMS on your Webdock server with these instructions!
Last updated: September 2nd 2024
-
How to Install cPanel on a Webdock Ubuntu Server
Instructions for setting up cPanel on an Ubuntu server
Last updated: September 23rd 2024