Day 26 : Jenkins Declarative Pipeline.

Day 26 : Jenkins Declarative Pipeline.

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 a Jenkinsfile, which is a text file that contains the stages and steps of the pipeline. The Jenkinsfile can be stored in a version control system like Git 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 the pipeline as a code in Jenkins. It was designed as a general-purpose DSL (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

Screenshot from 2023-04-09 12-59-49

  • Description of file

Screenshot from 2023-04-09 13-04-18

  • Pipeline Script

Screenshot from 2023-04-09 13-04-31

  • Console Output

Screenshot from 2023-04-09 13-04-54

Screenshot from 2023-04-09 13-05-13

This is Simple Pipeline that prints out "Hello World" in stage logs.

Screenshot from 2023-04-09 13-05-43


Writing a Declarative Pipeline in Jenkins.

  • Declarative Script

Screenshot from 2023-04-09 13-15-09

  • Stage View

Screenshot from 2023-04-09 13-15-29

  • Console Output

Screenshot from 2023-04-09 13-16-14


Happy Learning :)

Did you find this article valuable?

Support DevOps by becoming a sponsor. Any amount is appreciated!