What does a scripted pipeline look like and when would you still write one?
IntermediateConceptScripted pipeline, Groovy & CPS
Answer
node('linux') {
stage('Checkout') { checkout scm }
stage('Build') {
try {
sh 'make build'
} catch (err) {
currentBuild.result = 'FAILURE'
throw err
} finally {
junit 'reports/*.xml'
}
}
}
We still use scripted style inside shared library steps, for dynamically generated stages (one per service discovered at runtime), and for legacy jobs. For application Jenkinsfiles, declarative is the default.
More on Scripted pipeline, Groovy & CPS
What is CPS and why does Jenkins transform pipeline Groovy?AdvancedWhy does `java.io.NotSerializableException` happen in pipelines?AdvancedWhat does `@NonCPS` do and what are its rules?AdvancedWhy do some Groovy closures behave unexpectedly in pipelines, for example `list.each { }` or `sort`?AdvancedWhat is the `script` block in declarative, and what are its limits?BeginnerHow do you share a variable between stages in declarative?Intermediate