Declarative versus Scripted Pipeline: what are the differences?

IntermediateConceptJenkins
Answer

Declarative has a fixed structure (pipeline { agent, stages, steps, post }), built-in options (when, parallel, post, options), syntax validation before running, and is easier to read and lint. Scripted is a node { } block of full Groovy, offering unlimited flexibility (loops, try/catch, dynamic stages) but with no structural validation and more ways to write unmaintainable code.

Our rule is declarative by default, with a script { } block for the occasional dynamic bit, and complex logic moved into a shared library.

pipeline {
  agent { label 'linux' }
  stages {
    stage('Build') { steps { sh 'mvn -B -DskipTests package' } }
    stage('Test')  { steps { sh 'mvn -B test' } }
  }
  post { always { junit 'target/surefire-reports/*.xml' } }
}
All CI/CD questions

More on Jenkins