Jenkins Declarative Pipeline provides a structured and simplified way to define CI/CD pipelines. This article walks through the fundamental execution steps for beginners.
Key Steps in a Declarative Pipeline
- Pipeline Block: The outermost block that defines the entire pipeline configuration.
- Agent Section: Specifies where the pipeline runs (e.g.,
any,none, or a specific label). - Stages Block: Contains one or more
stageblocks, each representing a logical phase. - Steps Block: Inside each stage, defines the actual steps to execute (e.g., shell commands, build tools).
Example Pipeline
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Building...'
}
}
stage('Test') {
steps {
echo 'Testing...'
}
}
stage('Deploy') {
steps {
echo 'Deploying...'
}
}
}
}
Important Directives
- Post: Handles actions after stages (e.g., success/failure notifications).
- Environment: Sets environment variables.
- When: Adds conditional execution based on branch, status, etc.
Beginners should focus on mastering these core elements before exploring advanced features like shared libraries or parallel execution.
For a visual walkthrough, refer to the linked video tutorial.