Which statement correctly describes the main difference between scripted and declarative Jenkins pipelines?
Think about how each pipeline style expresses the build process: one is more like writing code, the other more like describing steps.
Scripted pipelines are written in Groovy and allow full programming control (imperative style). Declarative pipelines use a simpler, structured syntax focused on stages and steps, making them easier to read and write.
Given this declarative Jenkins pipeline snippet, what will be the output in the Jenkins console log?
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Building...'
}
}
stage('Test') {
parallel {
stage('Unit Tests') {
steps {
echo 'Running unit tests'
}
}
stage('Integration Tests') {
steps {
echo 'Running integration tests'
}
}
}
}
}
}Remember that parallel stages run at the same time, but their output appears sequentially in the log.
The pipeline first runs the 'Build' stage printing 'Building...'. Then the 'Test' stage runs two parallel stages, each printing their respective messages. All three messages appear in the log.
Which scripted Jenkins pipeline snippet correctly loops over a list of environments and echoes each one?
Check Groovy syntax for loops and list indexing carefully.
Option A uses a valid Groovy for-in loop. Option A has a syntax error with the each() call missing a closure parameter. Option A uses Python-like syntax which is invalid in Groovy. Option A has an off-by-one error in the loop condition causing an index out of bounds.
Why does this declarative pipeline snippet cause a syntax error?
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Building...'
}
}
stage('Test') {
steps {
parallel {
unit: {
echo 'Unit tests'
},
integration: {
echo 'Integration tests'
}
}
}
}
}
}Check the correct way to define parallel stages in declarative pipelines.
In declarative pipelines, parallel stages must be defined as nested 'stage' blocks inside the 'parallel' block. Using labels with closures directly inside 'steps' is invalid syntax.
You need to implement a Jenkins pipeline with complex conditional logic, loops, and dynamic stage creation. Which pipeline style is best suited for this task and why?
Consider which pipeline style supports full programming features like loops and dynamic stage creation.
Scripted pipelines use Groovy code, allowing complex programming constructs such as loops, conditionals, and dynamic stage creation. Declarative pipelines have a simpler syntax but limited support for such dynamic behavior.