The Best Way to Implement CI CD Pipeline Using Jenkins

Several organizations across the globe have shifted their focus towards automation or are trying to move towards it. And for good reason. What plays a significant role in this process is the adoption of the CI/CD pipeline. 

The process of building this Pipeline needs a flexible and powerful DevOps tool. Hence, the tool that comes into the picture for this is Jenkins. As we move forth with this article, we shall look at the step-by-step process of building a CI/CD pipeline using Jenkins.

The topics we will be covering in this article are the following:

  • What is DevOps?
  • What is a CI/CD Pipeline?
  • What is Jenkins?
  • Building CI/CD Pipeline with Jenkins
  • Demo - To Build a CI/CD Pipeline with Jenkins 

What is DevOps?

DevOps is a software engineering approach or culture that unifies the Development and Operations team under an umbrella of tools to automate every stage. The Development team is responsible for coding or scripting the software and integrating all the components needed to run that software. Meanwhile, the Operations team is responsible for managing the organization's diverse workforce to ensure effective and efficient daily operations.

DEV_and_OPS

There are various milestones that DevOps helps in achieving:

  • Frequent Release of Deliverables
  • Team Collaboration
  • Build Management of Unplanned Work
  • Faster Resolution of Issues

Now, let's have a look at the Pipeline that is making DevOps so popular today.

Post Graduate Program in DevOps

Designed in collaboration with Caltech CTMEExplore Course
Post Graduate Program in DevOps

What is a CI/CD Pipeline?

CI/CD pipeline refers to the Continuous Integration/Continuous Delivery pipeline. Before we dive deep into this segment, let's first understand what is meant by the term ‘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 some steps. All the steps in phase one have to be completed, to mark the latter stage to be complete. 

CI_CD_pipeline_with_Jenkins

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.

Continuous_Integration

Before we tell you how to build this CI/CD pipeline using Jenkins, let us look into 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 verifications 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 in which 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 could be referred to as automated, and this process is 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.

The DevOps tool that is most commonly used for a CI/CD pipeline is Jenkins. So, we must have a look at the basics of Jenkins and understand why it is the most sought after tool to build this pipeline.

Jenkins Certification Training Course

Learn server automation, CI/CD, and more.Explore Course
Jenkins Certification Training Course

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.

jenkins

Jenkins turns out to be the best fit for building a CI/CD pipeline because of its flexibility, openness, plugin-capabilities, and simple to use nature.

Building CI/CD Pipeline with Jenkins

There are six steps to building a pipeline with Jenkins. But, before you begin those six steps, make sure you have the following in your system.

  • Java Development Kit
  • Knowledge to execute some basic Linux commands

The steps to build CI/CD pipeline with Jenkins are:

1. Download Jenkins

Download_Jenkins

2. Execute Jenkins as a Java binary

  • Open the terminal window and enter cd <your path>.
  • Use the command java –jar ./Jenkins. war to run the WAR file.

3. Create a Jenkins Job

  • Open the web browser and open localhost:8080.
  • The Jenkins dashboard opens creates new jobs there.

create_pipeline

4. Create a Pipeline Job

  • Select and define what Jenkins job that is to be created.
  • Select Pipeline, give it a name and click OK.
  • Scroll down and find the pipeline section.
  • Either directly write a pipeline script or retrieve the Jenkins file from SCM (Source Code Management).

5. Configure and Execute a Pipeline Job With a Direct Script

  • Choose Pipeline script as the Destination and paste the Jenkins file content in the Script from the GitHub.
  • Click on Save to keep the changes.
  • Now click on the Build Now to process the build.
  • To check the output, click on any stage and click Log; a message will appear on the screen.

6. Configure and Execute a Pipeline With SCM

  • Copy the GitHub repository URL by clicking on Clone or download.
  • Now, click on Configure to modify the existing job.
  • Scroll to the Advanced Project Options setting and select Pipeline script from the SCM option.
  • Paste the GitHub repository URL here.
  • Type Jenkinsfile in the Script, and then click on the Save button.
  • Next, click on Build Now to execute the job again.
  • There will be an additional stage, in this case, i.e., Declaration: Checkout SCM.
  • Click on any stage and click on Log.

After you have understood all the essential steps to build a CI/CD pipeline using Jenkins, a hands-on demonstration will serve as a cherry on the cake.

DevOps Career Guide

A Guide to Becoming A DevOps EngineerDownload Now
DevOps Career Guide

Demo - To Build a CI/CD Pipeline With Jenkins

Go to your Jenkins Portal:

  • Click on ‘Create a job’.
  • In the item name dialog box, you may enter the ‘pipeline’.
  • Select the pipeline job type in the list below.
  • Click on OK.

Pipeline

A configuration related to the pipeline opens on the screen.

  • Scroll down on that page.
  • There in the dialog box, choose GitHub+Maven.

GitHub_Maven

Some steps will appear on the screen. The next step is to integrate the Jenkins file into the Version Control system.

So, for that

  • Select ‘Pipeline script from SCM’.

Pipeline_script_from_SCM.

  • Then in the SCM dialog box, select Git.
  • ‘Jenkins file’ is the name of the Script.
  • Add the Git repository URL.
  • You can add the credentials if any.

Git_Repository.

The credentials can be added with the help of the ‘Add’ option.

  • Then save the configuration

A page now comes on the screen that gives you various options like ‘Build Now’, ‘Delete Pipeline’, ‘Configure’, etc.

particular_page

  • Click on the Build Now option.

The pipeline will start downloading. The checkout will be visible on the screen and you can see the build being complete on the screen.

/Pipeline_pipeline

You can go to the console output option to check the log that is taking place.

You will soon be able to see that all the segments of the pipeline are completed. The artifact will be present to download. The war file can be downloaded using that link.

The entire process helps us understand how the whole Pipeline is configured. Using similar types of steps, different kinds of automation pipelines can be configured.

Check out the Jenkins Certification Training Course to learn server automation, continuous integration, build pipelines, configuration tools, and more. Enroll now!

Conclusion

By now, this article would have helped you thoroughly understand the basics of the CI/CD pipeline and the steps to build a CI/CD pipeline using Jenkins. We hope the hands-on demo helped you to learn all the integral parts that are to be kept in mind while following the steps to build a CI/CD pipeline.

If you are planning to learn CI/CD pipeline and excel in DevOps, consider enrolling in Simplilearn’s DevOps certification training course. Certification will act as a catalyst to boost your career in the field of DevOps.

Do you have any questions for us? Reach out to us by mentioning them in the comment section of this article. We’ll have our experts look into them and provide answers as soon as possible.

About the Author

Ishan GabaIshan Gaba

Ishan Gaba is a Research Analyst at Simplilearn. He is proficient in Java Programming, Data Structures, and Project Management. Graduated in Information Technology, Ishan is also passionate about writing and traveling.

View More
  • Disclaimer
  • PMP, PMI, PMBOK, CAPM, PgMP, PfMP, ACP, PBA, RMP, SP, and OPM3 are registered marks of the Project Management Institute, Inc.