Bird
Raised Fist0
Jenkinsdevops~20 mins

Pipeline stages and steps in Jenkins - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Pipeline Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output of a simple Jenkins pipeline with stages
What will be the output in the Jenkins console log after running this pipeline?
Jenkins
pipeline {
  agent any
  stages {
    stage('Build') {
      steps {
        echo 'Building project'
      }
    }
    stage('Test') {
      steps {
        echo 'Running tests'
      }
    }
  }
}
A[Pipeline] stage\n[Pipeline] { (Test)\n[Pipeline] echo\nRunning tests\n[Pipeline] }\n[Pipeline] stage\n[Pipeline] { (Build)\n[Pipeline] echo\nBuilding project\n[Pipeline] }
B[Pipeline] stage\n[Pipeline] { (Build)\n[Pipeline] echo\nBuilding project\n[Pipeline] }\n[Pipeline] stage\n[Pipeline] { (Test)\n[Pipeline] echo\nRunning tests\n[Pipeline] }
C[Pipeline] stage\n[Pipeline] { (Build)\n[Pipeline] echo\nRunning tests\n[Pipeline] }\n[Pipeline] stage\n[Pipeline] { (Test)\n[Pipeline] echo\nBuilding project\n[Pipeline] }
D[Pipeline] stage\n[Pipeline] { (Build)\n[Pipeline] echo\nBuilding project\n[Pipeline] }\n[Pipeline] stage\n[Pipeline] { (Test)\n[Pipeline] echo\nBuilding project\n[Pipeline] }
Attempts:
2 left
💡 Hint
Stages run in the order they are defined.
🧠 Conceptual
intermediate
1:30remaining
Understanding parallel stages in Jenkins pipeline
Which statement about parallel stages in Jenkins pipeline is true?
AParallel stages run one after another in sequence.
BParallel stages cannot contain steps.
CParallel stages must be defined outside the stages block.
DParallel stages run simultaneously, allowing multiple tasks at the same time.
Attempts:
2 left
💡 Hint
Think about how parallel means 'at the same time'.
❓ Configuration
advanced
2:30remaining
Correct syntax for a Jenkins pipeline with parallel stages
Which pipeline code correctly defines two parallel stages named 'Test1' and 'Test2' that echo different messages?
A
pipeline {
  agent any
  stages {
    stage('ParallelTests') {
      parallel {
        stage('Test1') {
          steps { echo 'Running Test1' }
        }
        stage('Test2') {
          steps { echo 'Running Test2' }
        }
      }
    }
  }
}
B
pipeline {
  agent any
  stages {
    parallel {
      stage('Test1') {
        steps { echo 'Running Test1' }
      }
      stage('Test2') {
        steps { echo 'Running Test2' }
      }
    }
  }
}
C
pipeline {
  agent any
  stages {
    stage('Test1') {
      parallel {
        steps { echo 'Running Test1' }
      }
    }
    stage('Test2') {
      steps { echo 'Running Test2' }
    }
  }
}
D
pipeline {
  agent any
  stages {
    stage('ParallelTests') {
      steps {
        parallel {
          Test1: { echo 'Running Test1' },
          Test2: { echo 'Running Test2' }
        }
      }
    }
  }
}
Attempts:
2 left
💡 Hint
Parallel block must be inside a stage, and parallel stages are nested inside it.
❓ Troubleshoot
advanced
2:00remaining
Identifying error in Jenkins pipeline stage definition
What error will this Jenkins pipeline produce?
Jenkins
pipeline {
  agent any
  stages {
    stage('Build')
      steps {
        echo 'Building'
      }
    }
  }
}
ASyntaxError: Expected a block after stage declaration
BRuntimeError: Missing agent declaration
CNo error, pipeline runs successfully
DTypeError: steps block misplaced
Attempts:
2 left
💡 Hint
Check the braces and indentation after the stage keyword.
🔀 Workflow
expert
3:00remaining
Order of execution in a Jenkins pipeline with nested stages
Given this pipeline, what is the order of echo outputs in the console log?
Jenkins
pipeline {
  agent any
  stages {
    stage('Deploy') {
      stages {
        stage('Deploy to Dev') {
          steps { echo 'Deploying to Dev' }
        }
        stage('Deploy to Prod') {
          steps { echo 'Deploying to Prod' }
        }
      }
    }
    stage('Cleanup') {
      steps { echo 'Cleaning up' }
    }
  }
}
ACleaning up\nDeploying to Dev\nDeploying to Prod
BDeploying to Dev\nCleaning up\nDeploying to Prod
CDeploying to Dev\nDeploying to Prod\nCleaning up
DDeploying to Prod\nDeploying to Dev\nCleaning up
Attempts:
2 left
💡 Hint
Nested stages run in order inside their parent stage before moving on.

Practice

(1/5)
1. What is the main purpose of stages in a Jenkins pipeline?
easy
A. To define environment variables
B. To run shell commands directly
C. To divide the pipeline into distinct parts for clarity
D. To store pipeline logs

Solution

  1. Step 1: Understand the role of stages

    Stages are used to split the pipeline into clear sections, making it easier to read and manage.
  2. Step 2: Differentiate stages from steps

    Steps are the actual commands or actions inside stages, not the division itself.
  3. Final Answer:

    To divide the pipeline into distinct parts for clarity -> Option C
  4. Quick Check:

    Stages divide pipeline parts = C [OK]
Hint: Stages split pipeline parts; steps run commands inside [OK]
Common Mistakes:
  • Confusing stages with steps
  • Thinking stages run commands directly
  • Assuming stages store logs
2. Which of the following is the correct syntax to define a stage named Build in a Jenkins declarative pipeline?
easy
A. stages { Build { steps { echo 'Building...' } } }
B. stage: Build { steps { echo 'Building...' } }
C. stage { name: 'Build' steps { echo 'Building...' } }
D. stage('Build') { steps { echo 'Building...' } }

Solution

  1. Step 1: Recall declarative pipeline stage syntax

    The correct syntax uses stage('Name') { ... } to define a stage.
  2. Step 2: Check the options for correct structure

    stage('Build') { steps { echo 'Building...' } } matches the correct syntax with stage('Build') { steps { ... } }.
  3. Final Answer:

    stage('Build') { steps { echo 'Building...' } } -> Option D
  4. Quick Check:

    Stage syntax uses stage('name') { steps { ... } } = A [OK]
Hint: Use stage('Name') { steps { ... } } for stages [OK]
Common Mistakes:
  • Using colon instead of parentheses for stage name
  • Placing stage inside stages incorrectly
  • Missing quotes around stage name
3. Given this Jenkins pipeline snippet, what will be the output when the pipeline runs?
pipeline {
  agent any
  stages {
    stage('Test') {
      steps {
        echo 'Running tests'
      }
    }
  }
}
medium
A. Running tests
B. Build stage executed
C. Syntax error
D. No output

Solution

  1. Step 1: Identify the stage and steps

    The pipeline has one stage named 'Test' with a step that echoes 'Running tests'.
  2. Step 2: Understand echo step output

    The echo step prints the given string to the console output when the pipeline runs.
  3. Final Answer:

    Running tests -> Option A
  4. Quick Check:

    Echo prints 'Running tests' = A [OK]
Hint: Echo prints text inside steps during stage run [OK]
Common Mistakes:
  • Thinking stage name prints output
  • Assuming syntax error without checking carefully
  • Expecting output from missing steps
4. Identify the error in this Jenkins pipeline snippet:
pipeline {
  agent any
  stages {
    stage('Deploy')
      steps {
        echo 'Deploying app'
      }
  }
}
medium
A. Steps block should be outside stages
B. Missing curly braces after stage declaration
C. Echo command syntax error
D. Incorrect agent declaration

Solution

  1. Step 1: Check stage syntax

    The stage block must have curly braces enclosing its content: stage('Deploy') { ... }.
  2. Step 2: Identify missing braces

    In the snippet, the stage declaration lacks opening and closing braces around steps.
  3. Final Answer:

    Missing curly braces after stage declaration -> Option B
  4. Quick Check:

    Stage needs braces { } = D [OK]
Hint: Always use braces {} after stage('name') [OK]
Common Mistakes:
  • Forgetting braces after stage name
  • Placing steps outside stages block
  • Misunderstanding agent syntax
5. You want to create a Jenkins pipeline with two stages: Build and Test. The Test stage should only run if the Build stage succeeds. Which pipeline snippet correctly implements this logic?
hard
A. pipeline { agent any stages { stage('Build') { steps { echo 'Building...' } } stage('Test') { steps { echo 'Testing...' } } } }
B. pipeline { agent any stages { stage('Build') { steps { echo 'Building...' } } stage('Test') { when { expression { currentBuild.result == 'SUCCESS' } } steps { echo 'Testing...' } } } }
C. pipeline { agent any stages { stage('Build') { steps { echo 'Building...' } } stage('Test') { when { branch 'main' } steps { echo 'Testing...' } } } }
D. pipeline { agent any stages { stage('Build') { steps { echo 'Building...' } } stage('Test') { steps { echo 'Testing...' } } } post { success { echo 'Build succeeded' } } }

Solution

  1. Step 1: Understand conditional stage execution

    Jenkins declarative pipelines run stages sequentially by default. If the Build stage fails, the Test stage is skipped.
  2. Step 2: Check the snippet with sequential stages

    pipeline {
      agent any
      stages {
        stage('Build') {
          steps {
            echo 'Building...'
          }
        }
        stage('Test') {
          steps {
            echo 'Testing...'
          }
        }
      }
    }
  3. Step 3: Verify distractors

    The snippet with when { expression { currentBuild.result == 'SUCCESS' } } uses the correct property result instead of currentResult.
    The snippet with when { branch 'main' } conditions on Git branch.
    The snippet with post { success { ... } } adds an unrelated post-action block.
  4. Final Answer:

    pipeline { agent any stages { stage('Build') { steps { echo 'Building...' } } stage('Test') { steps { echo 'Testing...' } } } } -> Option A
  5. Quick Check:

    Sequential stages run conditionally by default = A [OK]
Hint: Stages run sequentially by default; failure skips subsequent stages [OK]
Common Mistakes:
  • Using invalid when expression syntax
  • Conditioning on branch instead of stage success
  • Adding unnecessary post blocks
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