Table of contents
What is a Jenkins Declarative Pipeline?
A Declarative Pipeline is a structured way to define Jenkins Pipelines using a predefined format. It follows a scripted syntax but is easier to read and maintain compared to traditional scripted pipelines.
๐ Creating a Jenkins Declarative Pipeline
Step 1: Create a New Pipeline Job
Open Jenkins Dashboard.
Click New Item
Enter a name for the job.
Select Pipeline and click OK
Step 2: Define the Pipeline Script
In the Pipeline Definition section, select Pipeline Script and enter the following:
pipeline {
agent any
stages {
stage('Hello') {
steps {
echo 'Hello World...'
}
}
stage('Create Folder') {
steps {
echo 'creating folder...'
sh 'mkdir -p devops'
}
}
stage('Bye') {
steps {
echo 'Bye...'
}
}
}
}
Step 3: Save and Run the Pipeline
Click Save
Click Build Now to execute the pipeline
๐ Advantages of Declarative Pipelines
Easier to read and maintain due to structured syntax.
Supports version control by storing pipelines in a Jenkinsfile.
Error handling with built-in validation.
Modular stages make debugging easier.
๐ Freestyle Project vs. Declarative Pipeline: Which One to Use?
Feature | Freestyle Project | Declarative Pipeline |
Configuration Method | UI-based | Code (Jenkinsfile) |
Complexity | Low | Medium-High |
Version Control | Limited | Fully supported |
Flexibility | Basic steps | Advanced workflows |
Recommended For | Small projects, beginners | Large projects, teams with CI/CD experience |
Conclusion
Jenkins Freestyle Projects provide an easy way to automate build and deployment tasks with minimal setup, while Declarative Pipelines offer a scalable, version-controlled approach for CI/CD workflows. Understanding both methods allows you to choose the best fit for your project.
๐ Stay tuned for upcoming blogs on Multibranch Pipelines and Jenkinsfile Best Practices!