Day 26: Jenkins Declarative Pipeline Task – Completed! 🎉

🚀 Today’s Task: Exploring Jenkins Declarative Pipeline – the backbone of modern CI/CD practices.


What is a Pipeline?

A Pipeline in Jenkins is a collection of steps or jobs, arranged sequentially to automate building, testing, and deploying your application. With Jenkins, pipelines come in two flavors:

  1. Declarative: Modern, structured, and easier to read.

  2. Scripted: Groovy-based and more flexible but harder to manage.


Why Pipelines are Important?

  • Pipeline as Code: Written as a Jenkinsfile and stored in source control for versioning and collaboration.

  • Branch Builds: Automatically runs pipelines for branches and pull requests.

  • Code Review: Allows reviewing the pipeline definition alongside the application code.


My Task Progress

1️⃣ Created a New Pipeline Job:

  • In Jenkins, instead of a Freestyle Project, I selected the Pipeline type.

  • This allows me to write and manage the pipeline script.

2️⃣ Followed the Official Jenkins Hello World Example:

  • I referred to the official Jenkins documentation and implemented a Declarative Pipeline.

3️⃣ Wrote a Basic Jenkinsfile: Here’s the Jenkinsfile I used for this task:

pipeline {
    agent any

    stages {
        stage('Build') {
            steps {
                echo 'Building the application...'
            }
        }
        stage('Test') {
            steps {
                echo 'Running tests...'
            }
        }
        stage('Deploy') {
            steps {
                echo 'Deploying the application...'
            }
        }
    }
}

4️⃣ Committing the Jenkinsfile:

  • Added the Jenkinsfile to the project repository to follow best practices for Pipeline-as-Code.

What I Learned Today

  • The Declarative Pipeline syntax is user-friendly and structured, making it easy to manage even for beginners.

  • Writing a Jenkinsfile ensures pipelines are version-controlled and reviewed like application code.

  • Jenkins can automate builds, tests, and deployments seamlessly through pipelines.


0
Subscribe to my newsletter

Read articles from Amit singh deora directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Amit singh deora
Amit singh deora