0
0
Jenkinsdevops~20 mins

Steps within stages in Jenkins - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Master of Steps within Stages
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output of multiple steps in a Jenkins stage
Consider the following Jenkins pipeline stage snippet. What will be the output in the Jenkins console when this stage runs?
Jenkins
stage('Build') {
  steps {
    echo 'Step 1: Compile'
    echo 'Step 2: Test'
    echo 'Step 3: Package'
  }
}
AStep 1: Compile Step 2: Test Step 3: Package
BStep 1: Compile\nStep 2: Test\nStep 3: Package
CStep 3: Package\nStep 2: Test\nStep 1: Compile
DNo output is produced
Attempts:
2 left
💡 Hint
Remember Jenkins runs steps in the order they are written inside the stage.
Configuration
intermediate
2:00remaining
Correct syntax for multiple steps in a Jenkins stage
Which of the following Jenkins pipeline stage configurations correctly defines multiple steps inside a stage?
A
stage('Deploy') {
  steps {
    sh 'deploy.sh'
    echo 'Deployment complete'
  }
}
B
stage('Deploy') {
  sh 'deploy.sh'
  echo 'Deployment complete'
}
C
stage('Deploy') {
  steps: [sh 'deploy.sh', echo 'Deployment complete']
}
D
stage('Deploy') {
  step {
    sh 'deploy.sh'
    echo 'Deployment complete'
  }
}
Attempts:
2 left
💡 Hint
Steps must be inside the 'steps' block using curly braces.
Troubleshoot
advanced
2:00remaining
Why does this Jenkins stage fail to run all steps?
Given this Jenkins stage, only the first step runs and the others are skipped. What is the cause?
Jenkins
stage('Test') {
  steps {
    echo 'Running tests'
    return
    echo 'Tests complete'
  }
}
AJenkins requires each step to be inside its own 'steps' block.
BThe stage is missing a 'script' block to run multiple steps.
CThe 'echo' command is invalid and causes the stage to stop.
DThe 'return' statement exits the steps block early, so later steps are skipped.
Attempts:
2 left
💡 Hint
Think about what 'return' does inside a block of code.
🔀 Workflow
advanced
2:00remaining
Order of step execution in parallel and sequential stages
In this Jenkins pipeline snippet, which step runs last?
Jenkins
stage('Build') {
  steps {
    echo 'Compile'
  }
}
stage('Test and Package') {
  parallel {
    stage('Test') {
      steps {
        echo 'Run tests'
      }
    }
    stage('Package') {
      steps {
        echo 'Create package'
      }
    }
  }
}
stage('Deploy') {
  steps {
    echo 'Deploy application'
  }
}
A'Deploy application'
B'Create package'
C'Run tests'
D'Compile'
Attempts:
2 left
💡 Hint
Parallel stages run at the same time, but the next stage waits for them to finish.
Best Practice
expert
2:00remaining
Best practice for grouping multiple shell commands in a Jenkins step
Which option shows the best way to run multiple shell commands as a single step inside a Jenkins stage?
A
steps {
  sh 'command1 && command2 && command3'
}
B
steps {
  sh 'command1; command2; command3'
}
C
steps {
  sh '''
    command1
    command2
    command3
  '''
}
D
steps {
  sh 'command1'
  sh 'command2'
  sh 'command3'
}
Attempts:
2 left
💡 Hint
Think about readability and how Jenkins executes shell commands.