Process Flow - When to use scripted over declarative
Start Pipeline
Choose Pipeline Type
Declarative
The flow shows starting a Jenkins pipeline, choosing between declarative for simple, standard cases, or scripted for complex, custom logic needs.
pipeline {
agent any
stages {
stage('Build') {
steps { echo 'Building...' }
}
}
}| Step | Pipeline Type | Reason for Choice | Action Taken | Result |
|---|---|---|---|---|
| 1 | Declarative | Simple linear flow | Define stages and steps | Pipeline runs with clear structure |
| 2 | Declarative | Standard CI/CD tasks | Use built-in syntax | Easy to read and maintain |
| 3 | Scripted | Need complex logic | Write Groovy code with loops/conditions | Flexible control over flow |
| 4 | Scripted | Custom error handling | Use try-catch blocks | Handle errors precisely |
| 5 | Declarative | Limited scripting needed | Use scripted blocks inside declarative | Balance simplicity and flexibility |
| 6 | End | - | - | Pipeline completes or fails based on logic |
| Variable | Start | After Step 1 | After Step 3 | Final |
|---|---|---|---|---|
| pipelineType | undefined | declarative | scripted | scripted |
| stage | none | Build | Custom Logic | Custom Logic |
| errorHandled | false | false | true | true |
Jenkins pipelines come in two types: - Declarative: simple, readable, good for standard CI/CD - Scripted: flexible, Groovy-based, for complex logic Use declarative for most cases; use scripted when you need loops, conditions, or custom error handling. Declarative can include scripted blocks for extra flexibility.