Forgetting commas between map entries (not the main error here)
Assuming indentation causes syntax errors
5. You want to run three test suites in parallel in a Jenkins declarative pipeline and fail the entire build if any test fails. Which snippet correctly achieves this?
hard
A. stages {
stage('Parallel Tests') {
parallel {
Test1: { steps { sh 'run_test1.sh' } }
Test2: { steps { sh 'run_test2.sh' } }
Test3: { steps { sh 'run_test3.sh' } }
}
}
}
B. parallel {
stage('Test1') { steps { sh 'run_test1.sh' } }
stage('Test2') { steps { sh 'run_test2.sh' } }
stage('Test3') { steps { sh 'run_test3.sh' } }
}
C. stages {
parallel {
stage('Test1') { steps { sh 'run_test1.sh' } }
stage('Test2') { steps { sh 'run_test2.sh' } }
stage('Test3') { steps { sh 'run_test3.sh' } }
}
}
D. stage('Parallel Tests') {
parallel(
Test1: { sh 'run_test1.sh' },
Test2: { sh 'run_test2.sh' },
Test3: { sh 'run_test3.sh' }
)
}
Solution
Step 1: Recall declarative pipeline structure for parallel stages
Declarative pipelines require a stages block containing stage blocks; parallel tests go inside a single stage with a parallel block.
Step 2: Identify correct syntax for parallel tests with failure propagation
stages {
stage('Parallel Tests') {
parallel {
Test1: { steps { sh 'run_test1.sh' } }
Test2: { steps { sh 'run_test2.sh' } }
Test3: { steps { sh 'run_test3.sh' } }
}
}
} correctly uses stages block with a stage named 'Parallel Tests' containing a parallel block where each parallel branch is a closure with steps and sh commands. This is the proper declarative syntax and ensures the build fails if any test fails.
Final Answer:
stages {
stage('Parallel Tests') {
parallel {
Test1: { steps { sh 'run_test1.sh' } }
Test2: { steps { sh 'run_test2.sh' } }
Test3: { steps { sh 'run_test3.sh' } }
}
}
} -> Option A
Quick Check:
Declarative parallel inside a stage within stages block with steps closures [OK]
Hint: Use parallel inside a stage within stages block with steps closures [OK]
Common Mistakes:
Placing parallel outside stages block
Using parallel without wrapping in a stage
Mixing scripted and declarative syntax
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.