Skip to main content

Command Palette

Search for a command to run...

Day 26 Task: Jenkins Declarative Pipeline

Published
3 min readView as Markdown
Day 26 Task: Jenkins Declarative Pipeline

One of the most important parts of your DevOps and CICD journey is a Declarative Pipeline Syntax of Jenkins

Some terms for your Knowledge

What is Pipeline - A pipeline is a collection of steps or jobs interlinked in a sequence.

Declarative: Declarative is a more recent and advanced implementation of a pipeline as a code.

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.

Why you should have a Pipeline

The definition of a Jenkins Pipeline is written into a text file (called a Jenkinsfile) which in turn can be committed to a project’s source control repository.
This is the foundation of "Pipeline-as-code"; treating the CD pipeline as a part of the application to be versioned and reviewed like any other code.

Creating a Jenkinsfile and committing it to source control provides a number of immediate benefits:

  • Automatically creates a Pipeline build process for all branches and pull requests.

  • Code review/iteration on the Pipeline (along with the remaining source code).

  • Pipeline syntax

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

    Discuss with the help of a Task:

    Task-01

    1. Create a New Item, this time select the pipeline option not a Freestyle Project.

A) Create a Declarative pipeline in Jenkins, go to jenkins UI and click on New item.

No alt text provided for this image

Jenkins Dashboard Diagram.

B) Enter the pipeline name & select Pipeline,and the click on ok.

No alt text provided for this image

Enter a name select pipeline Diagram.

C) After create the pipeline, Now go to project configuration page, In general give a description of your project (I will add This is a Jenkins Pipeline Hello world).

No alt text provided for this image

In General option give a Description of the Pipeline Diagram.

D) Noe to to the 3rd option Pipeline (Definition option) scroll down select the pipeline script.

No alt text provided for this image

3Rd option Pipeline and add a Pipeline script Diagram.

E) Write a Pipeline Script of "Hello world"

No alt text provided for this image

Now Write a Script of "Hello World" Diagram.

Before i will move for the Build the Pipeline, Let's discuss a small Description of every points which are used for the Script.

1) Pipeline:- Declarative pipeline should start with the pipeline and this is the mandatory block.

2) Agent:- It specifies the jenkins build job should run. we have used the agent as any.

3) Stages:- It consists of the different executable stage block.

Steps:-

Steps block consist of the actual operation which needs to be performed inside Jenkins. in the Diagram i will use the "Hello World"

F) Build the project, you can manually build the project by clicking on the "Build now". link in the project's main page dashboard.

No alt text provided for this image

Click on the Build now Diagram.

G) After a build a completed, you can view the console output by clicking on the "Console output" in the build page.

No alt text provided for this image

Console Output of the Declaritive Jenkins Pipeline Diagram.

H) Now your pipeline are Successfully and Printed the "hello World"

I) you can see the each stage view by Clicking on the "Full stage View" in the project main page.

No alt text provided for this image

stage view by Clicking on the "Full stage View Diagram.

Now in the today, I have Successfully run the Declarative Pipeline inJenkins.

Thank you for reading this Article !! Stay Connected!!

Happy Learning!!

More from this blog

Untitled Publication

48 posts