Jenkins Pipelines samples
1. Agent Configuration Examples
1.1 Agent: Any (Free Executor/Slave)
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Running on any available agent'
sh 'mkdir -p abc'
sh 'ls -lart'
sh 'pwd'
}
}
}
}1.2 Agent: None (Schedule Stages on Different Agents)
1.3 Agent: Label (Schedule on Specific Agent)
1.4 Agent: Docker (Container-Based Execution)
2. Environment Variables & Variables in Pipelines
2.1 Basic Environment Variables
2.2 Environment Variables with Shell Variable Expansion
3. Parameters in Pipelines
3.1 Pipeline Parameters with String Input
4. Pipeline Options
4.1 Options: Retry, Build Discarder, Timeout, Timestamps
4.2 Stage-Level Retry Option
5. Parallel Stages
5.1 Running Multiple Stages in Parallel
6. Try-Catch Error Handling
6.1 Exception Handling with Try-Catch
7. Directory Navigation with dir()
7.1 Running Steps in Specific Directory
8. Triggers
8.1 Cron Trigger (Scheduled)
8.2 Poll SCM Trigger
9. Post Section - Pipeline Notifications
9.1 Post Actions: Always, Success, Failure
9.2 Stage-Level Post Actions
10. Conditional Execution with When
10.1 When: Single Expression
10.2 When: anyOf (OR condition)
10.3 When: allOf (AND condition)
10.4 When with Parameters
11. Git & Build Integration
11.1 Git Checkout with Credentials
11.2 Complete Maven Build Pipeline
Last updated
