Jenkins Declarative Pipeline

Jenkins Declarative Pipeline

ยท

2 min read

#90daysdevopschallenge

#day26

If you are new to Jenkins then Please go through from basic:

Jenkins-Basic

Pipeline:

The Pipeline is a collection of jobs and events that are interlinked with one another in a sequence.

JenkinsFile:

Jenkins pipeline can be defined by a text file called JenkinsFile. By using JenkinsFile you can implement a pipeline as a code and this can be defined by using DSL (Domain Specific Language). You can make pipelines automatically for all branches and can execute pull requests with just one JenkinsFile.

In Jenkins two types of syntax you can use to define the pipeline.

Declarative Pipeline:

Declarative is a more recent and advanced implementation of a pipeline as a code. Its syntax offers a simple way to create a pipeline.

Scripted Pipeline:

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.

Pipeline syntax

pipeline {
    agent any 
    stages {
        stage('Build') { 
            steps {
                // 
            }
        }
        stage('Test') { 
            steps {
                // 
            }
        }
        stage('Deploy') { 
            steps {
                // 
            }
        }
    }
}

Jenkins Pipeline Concepts:

Pipeline:

This is the user-defined block, which contains all the processes such as build, test, deploy, etc. It is a group of all the stages in JenkinsFile.

Syntax: pipeline{ }

Stage:

This block contains a series of steps in the pipeline.

pipeline {
    agent any 
    stages {
        stage('Build') { 
            steps {
                // 
            }
        }
     }
  }

Step:

A Step is a single task that executes a specific process at a defined time. A pipeline defines a series of steps defined within a stage block.

pipeline {
    agent any 
    stages {
        stage('Build') { 
            steps {
                // 
            }
        }
     }
  }

Task-01

Create a New Job, this time select Pipeline instead of Freestyle Project. Create a new pipeline for printing the "Hello World!".

Step 1: Create a new job.

Step 2: Enter the name of the pipeline and select "pipeline".

Step 3: Write the Script for the pipeline and click on "Save".

Step 4: Run the pipeline by clicking on "Build Now".

Step 5: After Successfully running the pipeline. Check the Console Output.

In the Next Article will read more about Jenkins Pipeline with docker..

Thank you for giving your precious time to read this blog/article and if any suggestions or improvements are required on my blogs feel free to connect on LinkedIn Unnati Gupta.

ย