0
0
Jenkinsdevops~20 mins

Deployment pipelines (dev, staging, prod) in Jenkins - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Deployment Pipeline Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
1:30remaining
Jenkins Pipeline Stage Execution Order

Given this Jenkins pipeline snippet, what will be the order of stage execution?

pipeline {
  agent any
  stages {
    stage('Dev') {
      steps { echo 'Deploying to Dev' }
    }
    stage('Staging') {
      steps { echo 'Deploying to Staging' }
    }
    stage('Prod') {
      steps { echo 'Deploying to Prod' }
    }
  }
}
Jenkins
pipeline {
  agent any
  stages {
    stage('Dev') {
      steps { echo 'Deploying to Dev' }
    }
    stage('Staging') {
      steps { echo 'Deploying to Staging' }
    }
    stage('Prod') {
      steps { echo 'Deploying to Prod' }
    }
  }
}
A1,3,2
B3,2,1
C2,1,3
D1,2,3
Attempts:
2 left
💡 Hint

Stages run in the order they are defined in the Jenkinsfile.

Configuration
intermediate
2:00remaining
Correct Jenkinsfile Syntax for Conditional Deployment

Which Jenkinsfile snippet correctly deploys to Prod only if the branch is main?

A
stage('Prod') {
  when {
    branch 'main'
  }
  steps {
    echo 'Deploying to Prod'
  }
}
B
stage('Prod') {
  when {
    branch == 'main'
  }
  steps {
    echo 'Deploying to Prod'
  }
}
C
stage('Prod') {
  when {
    branch = 'main'
  }
  steps {
    echo 'Deploying to Prod'
  }
}
D
stage('Prod') {
  when {
    branch != 'main'
  }
  steps {
    echo 'Deploying to Prod'
  }
}
Attempts:
2 left
💡 Hint

Check the correct syntax for the when condition in Jenkins declarative pipeline.

Troubleshoot
advanced
2:30remaining
Jenkins Pipeline Fails on Staging Deployment

A Jenkins pipeline deploys successfully to Dev but fails at the Staging stage with this error:

ERROR: script returned exit code 1

Which option is the most likely cause?

AThe Staging deployment script has a command that returns a non-zero exit code.
BThe Jenkinsfile syntax is invalid causing the pipeline to fail before Staging.
CThe Dev stage is skipped, so Staging cannot run.
DThe Prod stage is running before Staging causing a conflict.
Attempts:
2 left
💡 Hint

Non-zero exit codes usually indicate a failure in shell commands.

🔀 Workflow
advanced
2:30remaining
Jenkins Pipeline with Manual Approval Before Production

Which Jenkins pipeline snippet correctly adds a manual approval step before deploying to Production?

A
stage('Prod') {
  steps {
    input 'Approve Production Deployment?'
    echo 'Deploying to Prod'
  }
}
B
stage('Prod') {
  steps {
    echo 'Deploying to Prod'
    input 'Approve Production Deployment?'
  }
}
C
stage('Prod') {
  steps {
    timeout(time: 1, unit: 'MINUTES') {
      input 'Approve Production Deployment?'
    }
    echo 'Deploying to Prod'
  }
}
D
stage('Prod') {
  when {
    input 'Approve Production Deployment?'
  }
  steps {
    echo 'Deploying to Prod'
  }
}
Attempts:
2 left
💡 Hint

Manual approval uses input step, and timeout is good practice to avoid hanging.

Best Practice
expert
3:00remaining
Best Practice for Managing Secrets in Jenkins Pipelines

What is the best practice for handling sensitive credentials like API keys in Jenkins pipelines for deployment to multiple environments?

AStore secrets directly in the Jenkinsfile as plain text variables.
BUse Jenkins Credentials Plugin to securely store and inject secrets during pipeline execution.
CCommit secrets encrypted in the source code repository and decrypt them in the pipeline.
DAsk users to input secrets manually every time the pipeline runs.
Attempts:
2 left
💡 Hint

Think about security and automation in pipelines.