Topics covered in this blog:
What is Pipeline?
Types of Jenkins Pipeline.
How to Use Jenkins Pipeline with Example Task.
One of the most important parts of your DevOps and CI/CD journey is a
Declarative Pipeline Syntax of Jenkins
What is Pipeline?
In Jenkins, a pipeline refers to a way of defining a sequence of stages that describe the steps of a software delivery process. This can include building, testing, and deploying code.
A
pipeline
can be defined in aJenkinsfile
, which is a text file that contains thestages
andsteps of the pipeline
. The Jenkinsfile can be stored in a version control system likeGit
along with the code it describes, allowing for the pipeline to be versioned alongside the code.
Types of Jenkins Pipeline :
Declarative
: Declarative is a more recent and advanced implementation of a pipeline as a code.
Example:
pipeline {
agent { docker { image 'node:16.17.1-alpine' } }
stages {
stage('build') {
steps {
sh 'node --version'
}
}
}
}
Scripted
: Scripted was the first and most traditional implementation of thepipeline as a code
in Jenkins. It was designed as a general-purposeDSL (Domain Specific Language)
built with Groovy.
Example:
node{
stage('Hello'){
echo 'Hello World'
}
}
Why should we have Pipeline in Jenkins?
- A pipeline in Jenkins offers automation, consistency, transparency, and collaboration, and enables continuous delivery, making it an essential tool for modern software development teams.
Task-01:
Create a New Job, this time select Pipeline instead of Freestyle Project.
Creation of Pipeline Project
Description of file
Pipeline Script
Console Output
This is Simple Pipeline that prints out "Hello World" in stage logs
.
Writing a Declarative Pipeline in Jenkins.
Declarative Script
Stage View
Console Output