Bird
Raised Fist0
Jenkinsdevops~20 mins

Steps within stages in Jenkins - Practice Problems & Coding Challenges

Choose your learning style10 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.

Practice

(1/5)
1. What is the main purpose of steps inside a Jenkins stage?
easy
A. To define the actual commands or actions Jenkins will execute
B. To name the stage in the pipeline
C. To set environment variables for the pipeline
D. To configure Jenkins plugins

Solution

  1. Step 1: Understand the role of stages

    Stages organize the pipeline into sections but do not run commands themselves.
  2. Step 2: Identify what steps do inside stages

    Steps contain the actual commands or scripts Jenkins executes during that stage.
  3. Final Answer:

    To define the actual commands or actions Jenkins will execute -> Option A
  4. Quick Check:

    Steps = commands inside stages [OK]
Hint: Steps run commands; stages just group them [OK]
Common Mistakes:
  • Confusing stage name with steps
  • Thinking steps configure plugins
  • Believing steps set environment variables
2. Which of the following is the correct syntax to define a step that prints 'Hello World' inside a Jenkins declarative pipeline stage?
easy
A. script { print 'Hello World' }
B. steps { echo 'Hello World' }
C. steps: echo('Hello World')
D. stage { echo 'Hello World' }

Solution

  1. Step 1: Recall declarative pipeline syntax for steps

    Inside a stage, steps are defined with the steps { ... } block.
  2. Step 2: Check the correct command to print

    The echo command prints messages in Jenkins pipelines.
  3. Final Answer:

    steps { echo 'Hello World' } -> Option B
  4. Quick Check:

    steps block + echo command = correct syntax [OK]
Hint: Use steps { echo 'text' } to print in Jenkins [OK]
Common Mistakes:
  • Using stage instead of steps for commands
  • Wrong colon syntax in steps
  • Using print instead of echo
3. Given this Jenkins pipeline snippet, what will be the output in the console?
stage('Build') {
  steps {
    echo 'Starting build'
    sh 'echo Build complete'
  }
}
medium
A. Syntax error in pipeline
B. Build complete\nStarting build
C. Starting build only
D. Starting build\nBuild complete

Solution

  1. Step 1: Understand the order of steps execution

    Steps run sequentially: first echo 'Starting build', then shell command sh 'echo Build complete'.
  2. Step 2: Determine console output

    The first prints 'Starting build', the shell prints 'Build complete', so output is both lines in order.
  3. Final Answer:

    Starting build\nBuild complete -> Option D
  4. Quick Check:

    Steps run in order, echo then shell output [OK]
Hint: Steps run top to bottom, echo then shell output [OK]
Common Mistakes:
  • Assuming shell output appears before echo
  • Thinking only echo prints
  • Confusing syntax causing errors
4. Identify the error in this Jenkins pipeline stage and how to fix it:
stage('Test') {
  steps
    echo 'Running tests'
}
medium
A. stage keyword should be inside steps
B. echo command is invalid; use print instead
C. Missing curly braces {} after steps; add steps { ... }
D. No error; pipeline is correct

Solution

  1. Step 1: Check syntax for steps block

    The steps block must have curly braces enclosing commands: steps { ... }.
  2. Step 2: Identify missing braces causing syntax error

    Here, steps is followed directly by echo without braces, which is invalid.
  3. Final Answer:

    Missing curly braces {} after steps; add steps { ... } -> Option C
  4. Quick Check:

    steps block requires braces { } [OK]
Hint: Always wrap steps commands inside steps { } [OK]
Common Mistakes:
  • Omitting braces after steps
  • Using print instead of echo
  • Placing stage inside steps
5. You want to run multiple shell commands sequentially inside a Jenkins stage. Which is the best way to organize these steps?
hard
A. Use a single sh step with commands separated by semicolons inside steps { }
B. Write multiple stage blocks, each with one sh command
C. Put all commands inside environment block
D. Use multiple steps blocks inside one stage

Solution

  1. Step 1: Understand how to run multiple shell commands

    Multiple commands can be run in one sh step by separating them with semicolons.
  2. Step 2: Identify correct pipeline structure

    Only one steps block is allowed per stage; multiple commands go inside one sh step or multiple steps inside the block.
  3. Final Answer:

    Use a single sh step with commands separated by semicolons inside steps { } -> Option A
  4. Quick Check:

    One steps block + one sh with multiple commands [OK]
Hint: Combine shell commands with semicolons inside one sh step [OK]
Common Mistakes:
  • Using multiple stages for commands
  • Trying multiple steps blocks inside one stage
  • Putting commands in environment block
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard