Day 26 - Navigating Jenkins' Declarative Pipeline Mastery ๐ŸŒŸ๐Ÿš€

Day 26 - Navigating Jenkins' Declarative Pipeline Mastery ๐ŸŒŸ๐Ÿš€

ยท

2 min read

๐ŸŒŸ Day 26 of the #90DaysOfDevOpsChallenge is here! Today, we're diving into the world of Jenkins Declarative Pipelines, a key aspect of modern CI/CD workflows. Let's break it down together! ๐Ÿš€

Understanding Jenkins Declarative Pipeline ๐Ÿ› ๏ธ

In your DevOps journey, mastering Jenkins Declarative Pipeline Syntax is crucial. But what exactly is it? ๐Ÿค”

Pipeline Essentials ๐Ÿ’ก

  • Pipeline: A sequence of interconnected steps or jobs.

  • Declarative vs. Scripted: Declarative pipelines, a more advanced approach, are written as code, while Scripted pipelines were the traditional method.

Why Pipelines Matter ๐ŸŒ Having a pipeline defined in a Jenkinsfile, stored in your project's source control, offers numerous benefits:

  • Automation: Automatically sets up a pipeline build process for all branches and pull requests.

  • Code Review: Facilitates code review and iteration on the pipeline, just like any other code in your project.

Getting Started with Declarative Pipelines ๐Ÿšง Let's dive into action with a simple example:

pipeline {
    agent any
    stages {
        stage('Build') {
            steps {
                // Your build steps here
            }
        }
        stage('Test') {
            steps {
                // Your testing steps here
            }
        }
        stage('Deploy') {
            steps {
                // Your deployment steps here
            }
        }
    }
}

In a Scripted pipeline, one or more 'node' blocks do the core work throughout the entire pipeline, however, this block is not mandatory but having the block does 2 things -

๐Ÿš€ Schedules the steps contained within the block to run by adding an item to the Jenkins queue. As soon as an executor is free on a node, the steps will run.

๐Ÿ“ Creates a workspace (a directory specific to that particular Pipeline) where work can be done on files checked out from the source control.

Jenkinsfile (Scripted Pipeline)
node {  
    stage('Build') { 
        // 
    }
    stage('Test') { 
        // 
    }
    stage('Deploy') { 
        // 
    }
}

Task-01: Your Challenge ๐ŸŽฏ

  1. Create a new Jenkins job, selecting Pipeline instead of a Freestyle Project.

  2. Follow the Official Jenkins Hello World example and complete it using the Declarative Pipeline.

    • Complete the example using the Declarative pipeline.

Conclusion ๐ŸŒŸ

Embrace the power of Jenkins Declarative Pipelines to streamline your CI/CD workflows and accelerate your software delivery. Keep exploring, experimenting, and honing your skills. Together, we're shaping the future of DevOps! ๐Ÿ’ช๐Ÿš€

Let's learn and grow together! ๐ŸŒฑ

Happy Learning and Happy Coding! ๐ŸŒŸ๐Ÿ‘จโ€๐Ÿ’ป

Did you find this article valuable?

Support Nilkanth Mistry by becoming a sponsor. Any amount is appreciated!

ย