Choose the best reason why scripted pipelines in Jenkins offer more flexibility compared to declarative pipelines.
Think about what programming features Groovy code provides.
Scripted pipelines are written in Groovy, which supports full programming features like loops and conditionals, enabling complex logic. Declarative pipelines have a more rigid structure.
What will be the output of this scripted pipeline snippet when the variable runTests is false?
def runTests = false
node {
stage('Build') {
echo 'Building...'
}
if (runTests) {
stage('Test') {
echo 'Testing...'
}
}
stage('Deploy') {
echo 'Deploying...'
}
}Check the condition controlling the 'Test' stage.
The 'Test' stage runs only if runTests is true. Since it is false, the pipeline skips the 'Test' stage and runs 'Build' and 'Deploy' stages.
Which scripted pipeline code correctly runs two stages in parallel?
Remember the syntax for the parallel step in scripted pipelines.
The parallel step takes a map of branch names to closures. Option A correctly uses this syntax. Other options misuse the syntax or steps.
Given this scripted pipeline snippet, why does Jenkins report groovy.lang.MissingMethodException?
node {
stage('Example') {
sh 'echo Hello'
}
stage('Example') {
sh 'echo World'
}
}Check the stage names and how Jenkins handles them.
Using the same stage name twice in a scripted pipeline causes Jenkins to confuse the method calls, leading to a missing method error.
In a scripted pipeline, what is the best way to share a variable's value between multiple stages?
Think about persistence and accessibility of variables across stages.
Environment variables (env) persist across stages and nodes, making them the best way to share values in scripted pipelines. Variables declared with def are local to their scope.