Jenkins is an open source automation server which enables developers around the world to reliably build, test, and deploy their software facilitating continuous integration(CI) and continuous delivery(CD). It is a server-based system that runs in servlet containers such as Apache Tomcat. Before we tell you how to build this CI/CD pipeline using Jenkins, let us investigate a brief meaning of these two terms: Continuous Integration and Continuous Delivery.
What is Continuous Integration (CI)?
Continuous Integration is a practice that integrates code into a shared repository. It uses automated verification for the early detection of problems. Continuous Integration doesn't eliminate bugs but helps in finding and removing them quickly.
What is Continuous Delivery (CD)?
Continuous Delivery is the phase where the changes are made in the code before deploying. The team in this phase decides what is to be deployed to the customers and when. The final goal of the pipeline is to make deployments.
When both these practices come together, all the steps are considered automated, resulting in the process we know as CI/CD. Implementation of CI/CD enables the team to deploy codes quickly and efficiently. The process makes the team more agile, productive, and confident.
Jenkins is the DevOps tool that is most used for CI/CD pipelines. Therefore, we must have a look at the basics of Jenkins and understand why it is the most sought-after tool to build this pipeline.
A pipeline is a concept that introduces a series of events or tasks that are connected in a sequence to make quick software releases. For example, there is a task, that task has got five different stages, and each stage has got several steps. All the steps in phase one must be completed, to mark the latter stage to be complete.
Now, consider the CI/CD pipeline as the backbone of the DevOps approach. This Pipeline is responsible for building codes, running tests, and deploying new software versions. The Pipeline executes the job in a defined manner by first coding it and then structuring it inside several blocks that may include several steps or tasks.
What is Jenkins?
Jenkins is an open-source automation tool used to build and test software projects. The tool makes it more convenient for developers to integrate changes to the project. Jenkins achieves Continuous Integration with the help of plugins. Please refer to the reference number 1-3 to know more about Jenkins.
Jenkins happens to be the best fit for building a CI/CD pipeline because of its flexibility, openness, plugin-capabilities, and ease of use.
How to Create Jobs in Jenkins?
To create jobs in Jenkins, we need to first download the Jenkins by using the URL: https://jenkins.io/download/. Reference 4 has steps to install Jenkins. Once Jenkins is installed, then to create the jobs follow below steps:
1. Click on New Item on the Jenkins dashboard.
2. Give the item name and choose the project from the list and then press OK.
3. Select the source code management.
4. Scroll down to Build section. Select execute shell from the dropdown of Add build step.
5. Write commands like Date and Echo. Click Apply and Save.
6. Click on Back to Dashboard and we will see the jobs have been created on the Jenkins dashboard.
How to Set up Build Pipeline in Jenkins.
Step1: Chain the required jobs in sequence Add upstream/downstream jobs
To set up Build Pipeline we first need to chain the required jobs in sequence. Please refer to the below figure to understand what is meant by chaining the jobs. As we showed earlier the Sample Build Job is our initial job and we want this job to run first followed by Sample Deploy Job, followed by Sample Test Job and then Sample Release Job at the very end.
Please follow the below steps to chain the required jobs in Jenkins.
a. Since Sample Build Job is our initial job, it doesn’t need any configurational change. Click on the dropdown selection of Sample Deploy Job and select Configure.
b. Check the small box in the Build Triggers section and write Sample Build Job because we want the Sample Build Job to run completely and run the Sample Deploy Job
c. Jobs in the other section can also be chained similarly.
Step2: Install Build Pipeline Plugin
a. To install Build Pipeline Plugin, click on Manage Jenkins on the dashboard.
b. Select Manage Plugins.
c. Search for Build Pipeline Plugin in the search bar. Install the Build Pipeline Plugin by clicking either of the install options. Click on back to Dashboard.
Step3: Add Build Pipeline view
To add Build Pipeline view:
a. Click in the (+) sign on the top of the Jenkins dashboard
b. Give the name and select Build Pipeline view from the radio button. Click OK.
c. Give the initial job name and number of displayed builds. Click on Apply and Save.
d. Below is the Build Pipeline View of the chained Jobs.
Jenkins Git Integration: Connecting to git and pulling the source code from GitHub
Steps for Jenkins Git Integration
1. Install Git Plugins
2. Install git in your Jenkins Server
a. Download Git SCM
b. Get the path of git.exe
3. Click on Manage Jenkins on the dashboard and select Global Test Configuration
4. Paste the path copied in Step (2b Step2). Click on Apply and Save.
5. Create the job by clicking New Item. Give the item name and choose the project from the list and then press OK.
6. Fill in the Job description and paste the project URL link from the GitHub. Click on Apply and then Save.
7. Select Git under Source Code Management and paste the repository URL. Please make a note that there is a difference between the project URL and repository URL. Click on Apply and then Save.
8. Select githubweb from the drop down and paste the project URL. Click on Apply and then Save.
In this blog, we learned how to create jobs and pipeline the jobs in Jenkins. We also learned how to integrate Jenkins and Git. It automates the build process quickly and delivers high quality software projects.