5. You want to create a Jenkins pipeline that builds, tests, and deploys a Spring Boot app only if tests pass. Which pipeline structure achieves this?
hard
A. pipeline {
agent any
stages {
stage('Build') { steps { sh 'mvn clean package' } }
stage('Deploy') { steps { sh './deploy.sh' } }
stage('Test') { steps { sh 'mvn test' } }
}
}
B. pipeline {
agent any
stages {
stage('Test') { steps { sh 'mvn test' } }
stage('Deploy') { steps { sh './deploy.sh' } }
stage('Build') { steps { sh 'mvn clean package' } }
}
}
C. pipeline {
agent any
stages {
stage('Build') { steps { sh 'mvn clean package' } }
stage('Test') { steps { sh 'mvn test' } }
stage('Deploy') { steps { sh './deploy.sh' } }
}
}
D. pipeline {
agent any
stages {
stage('Deploy') { steps { sh './deploy.sh' } }
stage('Build') { steps { sh 'mvn clean package' } }
stage('Test') { steps { sh 'mvn test' } }
}
}
Solution
Step 1: Understand stage order importance
Build must happen before testing, and deploy only after tests pass.
Step 2: Check pipeline stage sequence
pipeline {
agent any
stages {
stage('Build') { steps { sh 'mvn clean package' } }
stage('Test') { steps { sh 'mvn test' } }
stage('Deploy') { steps { sh './deploy.sh' } }
}
} has Build, then Test, then Deploy in correct order ensuring deploy runs only if tests succeed.
Final Answer:
Build, Test, then Deploy in sequence -> Option C
Quick Check:
Correct stage order ensures safe deploy [OK]
Hint: Deploy only after successful test stage [OK]
Common Mistakes:
Deploying before tests run
Running tests after deploy
Incorrect stage order breaking pipeline logic
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.