Introduction:
Today, we're diving deeper into the Jenkins Declarative Pipeline world and exploring how to leverage its power for even more efficient and organized pipeline management. But before we begin, let's start with a quick emoji-filled recap of what Jenkins Declarative Pipelines are all about: π
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 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:
Create a New Job, this time select Pipeline instead of Freestyle Project.
Printing Hello world.
Complete the example using the Declarative pipeline
Step 1: Click on New item and enter the item name and select Pipeline.
Step2: Add some job description and select Pipeline script and write the pipeline script to print Hello world!!
Step 3: Save and Click on Build now.
Conclusion:π
And there you have it! Day 26 of our Jenkins Declarative Pipelines journey is all about enhancing your pipelines with more stages, version control integration, and environment-specific behavior. Embrace the power of emojis to make your pipeline code not only functional but also a delight to work with! π€π»