Day26- 90DaysOfDevOps

Jenkins Declarative Pipeline

Day26- 90DaysOfDevOps

Hey Learners! Welcome back. As we automate our pipeline in the previous challenge, Today we'll dive deeper into the Jenkins Declarative pipeline and explore the most important part of the DevOps and CI/CD journey with the declarative pipeline syntax of Jenkins. Let's create the declarative pipeline.

Some terms for your Knowledge:-

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

Declarative Pipeline:- It's a more recent and advanced implementation of a pipeline as a code.

Scripted Pipeline:- Scripted pipeline 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 Jenkinsfile, which in turn can be committed to a project's source control repository.

This is a 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 several 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 {
                //
            }
        }
    }
}

Task 1-

In this task, we will print "Hello World!!!" with a Pipeline instead of a Freestyle Project.

  1. Create a New Job, this time select Pipeline instead of Freestyle Project.

  2. Go to the Pipeline section in the configuration and write a pipeline syntax as shown.

  3. Save the job Click Build Now and check the console output.

    For this task, we created only one stage as you can see below (in the pipeline too)

This is a simple project with the declarative pipeline. In upcoming challenges, we'll learn some advanced declarative pipelines.

Thank you so much for taking the time to read till the end! Hope you found this blog informative.

Feel free to explore more of my content, and don't hesitate to reach out if need any assistance from me or in case of you have any questions.

Find me on:- Hashnode LinkedIn Github

Happy Learning!