A. Pipeline skips build and test, runs deploy only
B. All stages run successfully including deploy
C. Build stage runs, then test stage fails and stops pipeline; deploy does not run
D. Pipeline runs build and deploy but skips test
Solution
Step 1: Analyze build stage
The build stage prints 'Building...' successfully.
Step 2: Analyze test stage
The test stage runs error 'Test failed!' which stops the pipeline with failure.
Step 3: Analyze deploy stage
Because test failed, deploy stage does not run.
Final Answer:
Build stage runs, then test stage fails and stops pipeline; deploy does not run -> Option C
Quick Check:
Failure in test stops pipeline before deploy [OK]
Hint: Error in test stage stops pipeline before deploy [OK]
Common Mistakes:
Assuming deploy runs despite test failure
Thinking error only logs message without stopping
Ignoring pipeline stop on error
4. You wrote this Jenkins pipeline snippet:
pipeline {
agent any
stages {
stage('build') {
steps {
sh 'make build'
}
}
stage('test') {
sh 'make test'
}
stage('deploy') {
steps {
sh 'make deploy'
}
}
}
}
Why does this pipeline fail to run correctly?
medium
A. The build stage uses sh instead of bat
B. The test stage is missing the steps block
C. The deploy stage should be outside stages
D. The agent keyword is misplaced
Solution
Step 1: Check syntax of each stage
Build and deploy stages have steps { ... } blocks, but test stage does not.
Step 2: Understand Jenkins syntax rules
Each stage must have a steps block to run commands; missing it causes failure.
Final Answer:
The test stage is missing the steps block -> Option B
Quick Check:
Missing steps block in stage = syntax error [OK]
Hint: Every stage needs a steps block for commands [OK]
Common Mistakes:
Forgetting steps block inside a stage
Mixing shell commands syntax
Misplacing agent keyword
5. You want to create a Jenkins pipeline that builds your app, runs tests, and deploys only if tests pass. Which pipeline structure below correctly implements this with proper stages and error handling?
hard
A. pipeline { agent any stages { stage('build') { steps { sh 'build.sh' } } stage('test') { steps { sh 'test.sh' } } stage('deploy') { steps { sh 'deploy.sh' } } } }
B. pipeline { agent any stages { stage('build') { steps { sh 'build.sh' } } stage('test') { steps { sh 'test.sh' } } stage('deploy') { steps { sh 'deploy.sh' } } } post { failure { echo 'Tests failed, skipping deploy' } } }
C. pipeline { agent any stages { stage('build') { steps { sh 'build.sh' } } stage('test') { steps { sh 'test.sh' } } stage('deploy') { steps { sh 'deploy.sh' } } } post { always { echo 'Deploying regardless of test result' } } }
D. pipeline { agent any stages { stage('build') { steps { sh 'build.sh' } } stage('test') { steps { sh 'test.sh' } } stage('deploy') { steps { sh 'deploy.sh' } } } post { success { echo 'Deployment complete' } } }
Solution
Step 1: Understand pipeline flow
Build runs first, then test, then deploy only if test passes (pipeline success).
Step 2: Analyze post blocks
pipeline { agent any stages { stage('build') { steps { sh 'build.sh' } } stage('test') { steps { sh 'test.sh' } } stage('deploy') { steps { sh 'deploy.sh' } } } post { success { echo 'Deployment complete' } } } uses post { success { ... } } to confirm deployment success message, matching requirement.
Step 3: Check other options
pipeline { agent any stages { stage('build') { steps { sh 'build.sh' } } stage('test') { steps { sh 'test.sh' } } stage('deploy') { steps { sh 'deploy.sh' } } } } lacks error handling; B prints message on failure but does not prevent deploy; C deploys always.
Final Answer:
Option D correctly runs deploy only on success and confirms deployment -> Option D
Quick Check:
Deploy runs only if tests pass = post success block [OK]
Hint: Use post success block to run deploy only if tests pass [OK]
Common Mistakes:
Deploy running even if tests fail
Missing post blocks for error handling
Confusing post always with success
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.