0
0
Jenkinsdevops~10 mins

Failing fast principle in Jenkins - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to stop the Jenkins pipeline immediately on failure.

Jenkins
pipeline {
  agent any
  stages {
    stage('Build') {
      steps {
        script {
          sh 'make build' || [1]
        }
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
Aerror('Build failed')
Becho 'Build failed'
Creturn
Dsleep 10
Attempts:
3 left
💡 Hint
Common Mistakes
Using echo only prints a message but does not stop the pipeline.
Using return does not fail the pipeline in this context.
Sleeping delays but does not stop the pipeline.
2fill in blank
medium

Complete the code to fail fast if tests do not pass.

Jenkins
stage('Test') {
  steps {
    script {
      def status = sh(script: 'make test', returnStatus: true)
      if (status != 0) [1]
    }
  }
}
Drag options to blanks, or click blank then click option'
Aerror('Tests failed')
Bsleep 5
Creturn
Decho 'Tests failed'
Attempts:
3 left
💡 Hint
Common Mistakes
Using echo only logs a message but does not stop the pipeline.
Using return does not fail the pipeline here.
Sleeping delays but does not fail the pipeline.
3fill in blank
hard

Fix the error in the Jenkins pipeline to fail fast on deployment failure.

Jenkins
stage('Deploy') {
  steps {
    script {
      def result = sh(script: 'deploy.sh', returnStatus: true)
      if (result == 0) {
        echo 'Deployment succeeded'
      } else [1]
    }
  }
}
Drag options to blanks, or click blank then click option'
Aecho 'Deployment failed'
Berror('Deployment failed')
Creturn
Dsleep 10
Attempts:
3 left
💡 Hint
Common Mistakes
Using echo only logs but does not stop the pipeline.
Using return does not fail the pipeline here.
Sleeping delays but does not stop the pipeline.
4fill in blank
hard

Fill both blanks to fail fast if linting or security scan fails.

Jenkins
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]
    }
  }
}
Drag options to blanks, or click blank then click option'
Aerror('Linting failed')
Becho 'Linting failed'
Cerror('Security scan failed')
Dsleep 5
Attempts:
3 left
💡 Hint
Common Mistakes
Using echo only logs messages but does not stop the pipeline.
Using sleep delays but does not fail the pipeline.
5fill in blank
hard

Fill all three blanks to fail fast if any critical step fails in this Jenkins pipeline.

Jenkins
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]
        }
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
Aerror('Build failed')
Berror('Tests failed')
Cerror('Deployment failed')
Decho 'Step failed'
Attempts:
3 left
💡 Hint
Common Mistakes
Using echo only logs messages but does not stop the pipeline.
Not handling all failure cases causes the pipeline to continue despite errors.