Bird
Raised Fist0
Jenkinsdevops~20 mins

Parallel stages execution in Jenkins - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Parallel Pipeline Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output of parallel stages in Jenkins pipeline

Consider this Jenkins pipeline snippet using parallel to run two stages simultaneously:

pipeline {
  agent any
  stages {
    stage('Parallel Stage') {
      parallel {
        stage('A') {
          steps {
            echo 'Running A'
          }
        }
        stage('B') {
          steps {
            echo 'Running B'
          }
        }
      }
    }
  }
}

What will be the order of the output lines in the Jenkins console?

Jenkins
pipeline {
  agent any
  stages {
    stage('Parallel Stage') {
      parallel {
        stage('A') {
          steps {
            echo 'Running A'
          }
        }
        stage('B') {
          steps {
            echo 'Running B'
          }
        }
      }
    }
  }
}
ARunning A and Running B lines can appear in any order or interleaved
BRunning B\nRunning A
CNo output because parallel stages do not print
DRunning A\nRunning B
Attempts:
2 left
💡 Hint

Think about how parallel execution affects output order.

❓ Configuration
intermediate
2:00remaining
Correct syntax for parallel stages in Jenkins scripted pipeline

Which of the following Jenkins scripted pipeline snippets correctly defines two parallel stages named 'Test' and 'Build'?

Jenkins
parallel(
  Test: {
    echo 'Testing'
  },
  Build: {
    echo 'Building'
  }
)
A
parallel(
  Test: {
    echo 'Testing'
  },
  Build: {
    echo 'Building'
  }
)
B
parallel([
  Test: {
    echo 'Testing'
  },
  Build: {
    echo 'Building'
  }
])
C
parallel {
  stage('Test') {
    echo 'Testing'
  }
  stage('Build') {
    echo 'Building'
  }
}
D
parallel(
  stage('Test') {
    echo 'Testing'
  },
  stage('Build') {
    echo 'Building'
  }
)
Attempts:
2 left
💡 Hint

Remember scripted pipeline uses parallel with a map of closures.

❓ Troubleshoot
advanced
2:00remaining
Why does a parallel stage fail to run all branches?

A Jenkins declarative pipeline uses parallel to run three branches: 'Lint', 'Test', and 'Deploy'. However, only 'Lint' and 'Test' run, and 'Deploy' is skipped without error. What is the most likely cause?

AParallel stages cannot have more than two branches
BThe 'Deploy' stage is inside a <code>when</code> condition that evaluates to false
CThe Jenkins agent does not support parallel execution
DThe 'Deploy' stage has a syntax error causing it to be ignored
Attempts:
2 left
💡 Hint

Check conditions that control stage execution.

🔀 Workflow
advanced
2:00remaining
Order of execution in nested parallel stages

Given this Jenkins declarative pipeline snippet:

pipeline {
  agent any
  stages {
    stage('Main') {
      parallel {
        stage('Branch1') {
          steps { echo 'Branch1' }
        }
        stage('Branch2') {
          parallel {
            stage('Sub1') {
              steps { echo 'Sub1' }
            }
            stage('Sub2') {
              steps { echo 'Sub2' }
            }
          }
        }
      }
    }
  }
}

Which statement about the output order is true?

A'Sub1' and 'Sub2' run sequentially after 'Branch1' completes
B'Branch1' always prints before 'Sub1' and 'Sub2'
COnly 'Branch1' runs because nested parallel is not supported
DOutput lines 'Branch1', 'Sub1', and 'Sub2' can appear in any order or interleaved
Attempts:
2 left
💡 Hint

Think about how nested parallel blocks behave.

✅ Best Practice
expert
3:00remaining
Best practice to handle failures in parallel stages

In a Jenkins pipeline with multiple parallel stages, what is the best practice to ensure that if one stage fails, the others continue running and the pipeline reports the failure at the end?

AUse <code>failFast true</code> in the parallel block to stop all on first failure
BDo not use parallel stages if failures are expected
CWrap each parallel stage steps in <code>try-catch</code> to catch errors and record failures manually
DUse <code>parallel</code> with <code>failFast false</code> and rely on Jenkins default behavior
Attempts:
2 left
💡 Hint

Consider how to isolate failures and still report them.

Practice

(1/5)
1. What is the main purpose of using the parallel block in a Jenkins pipeline?
easy
A. To run multiple stages at the same time to save time
B. To run stages one after another in a sequence
C. To pause the pipeline until manual approval
D. To restart the pipeline from the beginning

Solution

  1. Step 1: Understand the role of parallel block

    The parallel block allows multiple tasks or stages to run simultaneously in Jenkins.
  2. Step 2: Compare with other options

    Options A, B, and C describe restart, sequential execution, and manual pause, which are unrelated to parallel execution.
  3. Final Answer:

    To run multiple stages at the same time to save time -> Option A
  4. Quick Check:

    Parallel stages = run together [OK]
Hint: Parallel means tasks run at the same time, not one by one [OK]
Common Mistakes:
  • Thinking parallel means sequential execution
  • Confusing parallel with manual approval
  • Assuming parallel restarts the pipeline
2. Which of the following is the correct syntax to define parallel stages inside a Jenkins pipeline?
easy
A. stage('Build') { steps { echo 'Building' } parallel { stage('Test') { steps { echo 'Testing' } } } }
B. stage('Build') { parallel { stage('Test') { steps { echo 'Testing' } } } }
C. stage('Build') { steps { parallel { echo 'Building' } } }
D. parallel([ "Build": { steps { echo 'Building' } }, "Test": { steps { echo 'Testing' } } ])

Solution

  1. Step 1: Recall correct parallel syntax

    The parallel block should use a map of branches, each containing steps.
  2. Step 2: Analyze options

    parallel([ "Build": { steps { echo 'Building' } }, "Test": { steps { echo 'Testing' } } ]) correctly defines parallel branches. Options B, C, and D misuse the placement of parallel or stages.
  3. Final Answer:

    parallel([ "Build": { steps { echo 'Building' } }, "Test": { steps { echo 'Testing' } } ]) -> Option D
  4. Quick Check:

    parallel wraps stages directly [OK]
Hint: Parallel wraps multiple stages side by side, not inside one stage [OK]
Common Mistakes:
  • Putting parallel inside steps block
  • Nesting stages inside other stages incorrectly
  • Using parallel with single stage only
3. Given this Jenkins pipeline snippet, what will be the output order of the echo statements?
pipeline {
  agent any
  stages {
    stage('Parallel Stage') {
      steps {
        parallel (
          "A": {
            echo 'Running A'
          },
          "B": {
            echo 'Running B'
          }
        )
      }
    }
  }
}
medium
A. Running A\nRunning B
B. Running B\nRunning A
C. Running A and Running B in any order or simultaneously
D. Syntax error due to nested stages inside parallel

Solution

  1. Step 1: Understand parallel execution output

    Stages inside parallel run at the same time, so their output order is not guaranteed.
  2. Step 2: Check syntax validity

    The syntax is valid for parallel branches inside a stage's steps block, so no syntax error occurs.
  3. Final Answer:

    Running A and Running B in any order or simultaneously -> Option C
  4. Quick Check:

    Parallel stages output order is unpredictable [OK]
Hint: Parallel means output order can vary, no fixed sequence [OK]
Common Mistakes:
  • Assuming output order is always A then B
  • Thinking nested stages cause syntax error here
  • Expecting sequential output in parallel block
4. You wrote this Jenkins pipeline snippet but it fails with a syntax error:
pipeline {
  agent any
  stages {
    stage('Test') {
      steps {
        parallel {
          stage('Unit') {
            steps { echo 'Unit tests' }
          }
          stage('Integration') {
            steps { echo 'Integration tests' }
          }
        }
      }
    }
  }
}
What is the error and how to fix it?
medium
A. stage names inside parallel must be unique; rename stages
B. parallel block cannot contain nested stage blocks directly; use map syntax with branches
C. parallel block requires agent declaration inside each stage
D. steps block cannot contain echo commands

Solution

  1. Step 1: Identify parallel block syntax rules

    The parallel directive expects a map of branch names to closures containing steps, not loose stage blocks inside {}.
  2. Step 2: Fix the pipeline structure

    Change to parallel( "Unit": { echo 'Unit tests' }, "Integration": { echo 'Integration tests' } ) to fix the syntax error.
  3. Final Answer:

    parallel block cannot contain nested stage blocks directly; use map syntax with branches -> Option B
  4. Quick Check:

    parallel uses branch map syntax [OK]
Hint: parallel must be outside steps block, directly under stage [OK]
Common Mistakes:
  • Placing parallel inside steps block
  • Ignoring pipeline syntax hierarchy
  • Assuming echo commands cause error
5. You want to run three tasks in parallel: 'Build', 'Test', and 'Deploy'. The 'Deploy' stage should only run if both 'Build' and 'Test' succeed. How do you structure the Jenkins pipeline to achieve this?
hard
A. Use parallel for 'Build' and 'Test' stages, then a separate 'Deploy' stage after parallel block
B. Put all three stages inside a single parallel block
C. Run 'Deploy' inside parallel block with 'Build' and 'Test' but add a condition to skip if others fail
D. Run 'Deploy' before 'Build' and 'Test' in parallel block

Solution

  1. Step 1: Understand dependency requirements

    'Deploy' must wait for 'Build' and 'Test' to finish successfully, so it cannot run in parallel with them.
  2. Step 2: Structure pipeline accordingly

    Run 'Build' and 'Test' inside a parallel block, then add a separate 'Deploy' stage after that block to run only if previous succeed.
  3. Final Answer:

    Use parallel for 'Build' and 'Test' stages, then a separate 'Deploy' stage after parallel block -> Option A
  4. Quick Check:

    Dependent stage runs after parallel block [OK]
Hint: Run dependent stages after parallel block, not inside it [OK]
Common Mistakes:
  • Putting dependent stage inside parallel block
  • Running deploy before build and test
  • Trying to conditionally skip stages inside parallel
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