Jenkins is an automation tool providing continuous integration. It is open source and has been written in the Java Programming Language. It helps in the automation of software development parts that relate to build, test and deployment, and ensures constant delivery. What follows below is one aspect or you say the objective of the Jenkins Certification. Let us see how to create a CI/CD pipeline inside Jenkins.
Continuous Integration/Continuous Deployment is the backbone of DevOps. CI/CD fills the gap between development and operations team by automating the steps like build, test and deployment.
What is Jenkins Pipeline?
A Pipeline is a sequence of executable events or jobs. Jenkins itself does not perform any functionalities, it offers a way for other applications and tools to plug into Jenkins and execute the tasks.
The pipeline contains N number of stages and list of steps to be performed in each stage. A stage can be named as anything. A step is simply says what needs to be executed, and needs to be an executable command through Jenkins environment.
The Jenkins pipeline is typically given as a script called as a Jenkinsfile.
// Example Jenkins Pipeline Script pipeline { stages { stage('build') { steps { //Executable command as a step echo "This is an example jenkinsfile" sh 'mvn --version' } } } } //End of Pipeline
How to Build a Jenkins Pipeline?
Let us now see the steps to build Jenkins pipeline. Before starting, make sure you have Jenkins installed.
Open a web browser and navigate to Jenkins URL. In my case, it’s public IP address of amazon EC2 instance on port 8080.
Click on the “New Item” and define what kind of Jenkins job needs to be created. Select “Pipeline”, give it a name and click on ok.
On the next page, you will see pipeline configurations steps. There are two possible ways to execute Jenkins pipelines.
- Writing pipeline script directly on Jenkins
- Use the Jenkinsfile from SCM (source code management)
Configure a Pipeline Through Direct Script
On the pipeline configuration page, scroll down until the pipeline section. Copy the below code and paste it. I have used 3 stages in this example script, Building, Testing and Deploying. I have just printing some messages in each stage and executable steps.
//Sample script for configuring pipeline through direct script pipeline { agent any stages { stage('Building') { steps { echo 'Building Stage Running...' echo "Running ${env.BUILD_ID} ${env.BUILD_DISPLAY_NAME} on ${env.NODE_NAME} and JOB ${env.JOB_NAME}" } } stage('Testing') { steps { echo 'Testing Stage Running...' } } stage('Deploying') { steps { echo 'Deploying Stage Running...' } } } }
Save the configurations and click on Build Now.
Click on Logs to view the output of our script.
That’s it. We have successfully configured a pipeline through direct script.
Configure a Pipeline Through SCM
In this step, we will be using Jenkinsfile from the GitHub repository. Let us create a new job to perform this task.
On the pipeline configuration page, select the option “Pipeline Script from SCM” and SCM as “Git” then paste the GitHub repository URL. Type Jenkinsfile in script path and save the changes.
Note: Make sure you have git installed on your system or on the virtual machine where you have installed Jenkins. In my case, I am using EC2 instance with Amazon Linux. I have installed git using the below command.
sudo yum install git
Click on save and click “Build Now” to start the pipeline.
Summary
Hope we were able to clear the concept and this article may help you with Jenkins certification preparation. Plus this article was an addition to your already existing and polished knowledge base on Jenkins. If you want to pass the Jenkins certification exam on your first attempt, then spend more time on your learning. Stay tuned. Let’s catch up with another article soon!
- Top 10 Highest Paying Cloud Certifications in 2024 - March 1, 2023
- 12 AWS Certifications – Which One Should I Choose? - February 22, 2023
- 11 Kubernetes Security Best Practices you should follow in 2024 - May 30, 2022
- How to run Kubernetes on AWS – A detailed Guide! - May 30, 2022
- Free questions on CompTIA Network+ (N10-008) Certification Exam - April 13, 2022
- 30 Free Questions on Microsoft Azure AI Fundamentals (AI-900) - March 25, 2022
- How to Integrate Jenkins with GitHub? - March 22, 2022
- How to Create CI/CD Pipeline Inside Jenkins ? - March 22, 2022