0
0
Jenkinsdevops~20 mins

Rollback strategies in Jenkins - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Rollback Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding Blue-Green Deployment Rollback

In a Jenkins pipeline using blue-green deployment, what is the main advantage of the rollback strategy?

AIt requires manual intervention to switch environments.
BIt instantly switches traffic back to the previous stable environment without downtime.
CIt rebuilds the entire application from scratch before rollback.
DIt deletes the previous environment to save resources.
Attempts:
2 left
💡 Hint

Think about how blue-green deployment handles traffic between two environments.

💻 Command Output
intermediate
2:00remaining
Jenkins Pipeline Rollback Step Output

What is the output of this Jenkins pipeline snippet when rollback is triggered?

Jenkins
pipeline {
  agent any
  stages {
    stage('Deploy') {
      steps {
        script {
          def success = false
          if (!success) {
            error('Deployment failed, triggering rollback')
          }
        }
      }
    }
    stage('Rollback') {
      steps {
        echo 'Rollback started'
      }
    }
  }
  post {
    failure {
      echo 'Rollback started'
    }
  }
}
A
[Pipeline] { (Deploy)
[Pipeline] error
Deployment failed, triggering rollback
[Pipeline] }
[Pipeline] { (Rollback)
[Pipeline] echo
Rollback started
[Pipeline] }
[Pipeline] echo
Rollback started
B
[Pipeline] { (Deploy)
[Pipeline] echo
Rollback started
[Pipeline] }
[Pipeline] { (Rollback)
[Pipeline] error
Deployment failed, triggering rollback
C
[Pipeline] { (Deploy)
[Pipeline] echo
Deployment succeeded
[Pipeline] }
[Pipeline] { (Rollback)
[Pipeline] echo
Rollback started
[Pipeline] }
D
[Pipeline] { (Deploy)
[Pipeline] error
Deployment failed, triggering rollback
[Pipeline] }
[Pipeline] { (Rollback)
[Pipeline] echo
Deployment succeeded
[Pipeline] }
Attempts:
2 left
💡 Hint

Look at how the error and post failure blocks behave in Jenkins pipelines.

Configuration
advanced
2:30remaining
Configuring Jenkins Pipeline for Canary Rollback

Which Jenkins pipeline snippet correctly implements a canary deployment rollback by checking a health status and reverting if unhealthy?

A
pipeline {
  agent any
  stages {
    stage('Deploy Canary') {
      steps {
        script {
          def healthy = sh(script: 'curl -sf http://canary/health', returnStatus: true) == 1
          if (!healthy) {
            error('Canary unhealthy, rollback')
          }
        }
      }
    }
    stage('Rollback') {
      steps {
        echo 'Rolling back to previous version'
      }
    }
  }
  post {
    failure {
      echo 'Rollback triggered due to failure'
    }
  }
}
B
pipeline {
  agent any
  stages {
    stage('Deploy Canary') {
      steps {
        script {
          def healthy = sh(script: 'curl -sf http://canary/health', returnStatus: true) == 0
          if (healthy) {
            error('Canary unhealthy, rollback')
          }
        }
      }
    }
    stage('Rollback') {
      steps {
        echo 'Rolling back to previous version'
      }
    }
  }
  post {
    failure {
      echo 'Rollback triggered due to failure'
    }
  }
}
C
pipeline {
  agent any
  stages {
    stage('Deploy Canary') {
      steps {
        script {
          def healthy = sh(script: 'curl -sf http://canary/health', returnStatus: true)
          if (healthy) {
            error('Canary unhealthy, rollback')
          }
        }
      }
    }
    stage('Rollback') {
      steps {
        echo 'Rolling back to previous version'
      }
    }
  }
  post {
    failure {
      echo 'Rollback triggered due to failure'
    }
  }
}
D
pipeline {
  agent any
  stages {
    stage('Deploy Canary') {
      steps {
        script {
          def healthy = sh(script: 'curl -sf http://canary/health', returnStatus: true) == 0
          if (!healthy) {
            error('Canary unhealthy, rollback')
          }
        }
      }
    }
    stage('Rollback') {
      steps {
        echo 'Rolling back to previous version'
      }
    }
  }
  post {
    failure {
      echo 'Rollback triggered due to failure'
    }
  }
}
Attempts:
2 left
💡 Hint

Remember that sh returns 0 on success and non-zero on failure.

Troubleshoot
advanced
2:00remaining
Troubleshooting Jenkins Rollback Stage Not Executing

A Jenkins pipeline has a rollback stage defined after deployment. The rollback stage does not run even when deployment fails. What is the most likely cause?

AThe rollback stage uses <code>echo</code> instead of <code>sh</code> commands.
BThe rollback stage is not inside a <code>post { failure {}</code> block or not triggered by error.
CThe deployment stage uses <code>try-catch</code> to handle errors and does not rethrow them.
DThe rollback stage is defined before the deployment stage.
Attempts:
2 left
💡 Hint

Think about how Jenkins decides to run post or subsequent stages on failure.

🔀 Workflow
expert
3:00remaining
Optimizing Rollback Workflow in Jenkins Multibranch Pipeline

In a Jenkins multibranch pipeline, which workflow best ensures automatic rollback on failure while minimizing downtime and resource usage?

AUse a separate rollback stage triggered only in the <code>post { failure {}</code> block, which switches traffic back and cleans up failed deployment.
BAlways run rollback stage after deployment regardless of success, to ensure clean state.
CManually trigger rollback job outside the pipeline when failure is detected to avoid pipeline complexity.
DDeploy new version and keep old version running; rollback only after manual approval to save resources.
Attempts:
2 left
💡 Hint

Consider automation, downtime, and resource efficiency in your answer.