Complete the code to stop the Jenkins pipeline immediately on failure.
pipeline {
agent any
stages {
stage('Build') {
steps {
script {
sh 'make build' || [1]
}
}
}
}
}Using error('Build failed') stops the pipeline immediately when the build fails, following the failing fast principle.
Complete the code to fail fast if tests do not pass.
stage('Test') { steps { script { def status = sh(script: 'make test', returnStatus: true) if (status != 0) [1] } } }
The error('Tests failed') step immediately fails the pipeline if tests fail, implementing fail fast.
Fix the error in the Jenkins pipeline to fail fast on deployment failure.
stage('Deploy') { steps { script { def result = sh(script: 'deploy.sh', returnStatus: true) if (result == 0) { echo 'Deployment succeeded' } else [1] } } }
Using error('Deployment failed') causes the pipeline to stop immediately on deployment failure, following fail fast.
Fill both blanks to fail fast if linting or security scan fails.
stage('Quality Checks') { steps { script { def lintStatus = sh(script: 'lint.sh', returnStatus: true) if (lintStatus != 0) [1] def scanStatus = sh(script: 'security_scan.sh', returnStatus: true) if (scanStatus != 0) [2] } } }
Both error('Linting failed') and error('Security scan failed') stop the pipeline immediately on failure, implementing fail fast.
Fill all three blanks to fail fast if any critical step fails in this Jenkins pipeline.
pipeline {
agent any
stages {
stage('Critical Steps') {
steps {
script {
def buildStatus = sh(script: 'build.sh', returnStatus: true)
if (buildStatus != 0) [1]
def testStatus = sh(script: 'test.sh', returnStatus: true)
if (testStatus != 0) [2]
def deployStatus = sh(script: 'deploy.sh', returnStatus: true)
if (deployStatus != 0) [3]
}
}
}
}
}Each error() call stops the pipeline immediately on failure of build, test, or deploy steps, following the fail fast principle.