Bird
Raised Fist0
Jenkinsdevops~10 mins

Parallel test execution in Jenkins - Step-by-Step Execution

Choose your learning style10 modes available
Process Flow - Parallel test execution
Start Jenkins Pipeline
↓
Define parallel stages
↓
Trigger tests in parallel
↓
Wait for all tests to finish
↓
Collect and report results
↓
End
The Jenkins pipeline starts, defines multiple test stages to run at the same time, waits for all to finish, then collects results.
Execution Sample
Jenkins
pipeline {
  agent any
  stages {
    stage('Parallel Tests') {
      parallel {
        'Test A': {
          steps { echo 'Running Test A' }
        },
        'Test B': {
          steps { echo 'Running Test B' }
        }
      }
    }
  }
}
This Jenkins pipeline runs two test stages, Test A and Test B, at the same time.
Process Table
StepActionStage RunningOutputNotes
1Start pipelineNonePipeline startedPipeline begins execution
2Enter 'Parallel Tests' stageNoneEntering parallel blockPrepare to run parallel stages
3Start 'Test A' stageTest ARunning Test ATest A runs independently
4Start 'Test B' stageTest BRunning Test BTest B runs independently
5Wait for 'Test A' and 'Test B' to finishTest A, Test BBoth tests completeParallel stages complete
6Collect resultsNoneResults collectedPipeline gathers test outputs
7End pipelineNonePipeline finishedPipeline execution ends
💡 All parallel test stages complete, pipeline finishes.
Status Tracker
VariableStartAfter Step 3After Step 4After Step 5Final
Stage RunningNoneTest ATest A, Test BNoneNone
OutputPipeline startedRunning Test ARunning Test A, Running Test BBoth tests completePipeline finished
Key Moments - 2 Insights
Why do 'Test A' and 'Test B' run at the same time instead of one after the other?
Because they are defined inside the 'parallel' block (see execution_table steps 3 and 4), Jenkins runs these stages simultaneously to save time.
What happens if one parallel test fails?
The pipeline waits for all parallel stages to finish (step 5), but the overall pipeline may fail depending on the test results. This ensures all tests complete before reporting.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, at which step do both 'Test A' and 'Test B' run simultaneously?
AStep 4
BStep 2
CStep 3
DStep 5
💡 Hint
Check the 'Stage Running' column in steps 3 and 4 to see when both tests are active.
According to the variable tracker, what is the value of 'Stage Running' after step 4?
ANone
BTest A
CTest A, Test B
DTest B
💡 Hint
Look at the 'Stage Running' row in variable_tracker after step 4.
If we remove the 'parallel' block and run tests sequentially, how would the execution table change?
AThere would be no 'Parallel Tests' stage.
BSteps 3 and 4 would run one after another, not simultaneously.
CSteps 3 and 4 would still run at the same time.
DThe pipeline would skip tests.
💡 Hint
Parallel block controls simultaneous execution; removing it causes sequential runs.
Concept Snapshot
Jenkins Parallel Test Execution:
- Use 'parallel' block inside a stage to run multiple tests at once.
- Each test runs independently, saving time.
- Pipeline waits for all parallel tests to finish before continuing.
- Useful for speeding up test suites in CI pipelines.
Full Transcript
This visual execution shows how Jenkins runs tests in parallel. The pipeline starts, then enters a stage with a parallel block. Inside, Test A and Test B start at the same time. Jenkins waits for both to finish, then collects results and ends the pipeline. Variables track which stages run and outputs at each step. Key points include understanding that parallel stages run simultaneously and the pipeline waits for all to complete before moving on. The quiz checks understanding of when tests run together and how removing parallel changes execution.

Practice

(1/5)
1. What is the main purpose of using the parallel block in a Jenkins pipeline?
easy
A. To stop the pipeline if any test fails
B. To run multiple test groups at the same time to save time
C. To run tests one after another in a sequence
D. To deploy the application automatically after tests

Solution

  1. Step 1: Understand the parallel block function

    The parallel block in Jenkins allows running multiple tasks simultaneously.
  2. Step 2: Identify the benefit of parallel execution

    Running tests in parallel saves time by executing multiple test groups at once instead of sequentially.
  3. Final Answer:

    To run multiple test groups at the same time to save time -> Option B
  4. Quick Check:

    Parallel execution = run tests simultaneously [OK]
Hint: Parallel means running tasks at the same time [OK]
Common Mistakes:
  • Thinking parallel runs tests one by one
  • Confusing parallel with deployment steps
  • Assuming parallel stops on first failure
2. Which of the following is the correct syntax to run two test stages in parallel in a Jenkins declarative pipeline?
easy
A. parallel { stage('Test1') { steps { echo 'Run Test1' } } stage('Test2') { steps { echo 'Run Test2' } } }
B. parallel( Test1: { stage('Test1') { steps { echo 'Run Test1' } } }, Test2: { stage('Test2') { steps { echo 'Run Test2' } } } )
C. parallel( Test1: { echo 'Run Test1' }, Test2: { echo 'Run Test2' } )
D. parallel( Test1: { steps { echo 'Run Test1' } }, Test2: { steps { echo 'Run Test2' } } )

Solution

  1. Step 1: Recall Jenkins parallel syntax

    In declarative pipelines, parallel takes a map of closures using scripted syntax with direct steps like echo.
  2. Step 2: Check which option uses correct closure with direct steps

    parallel( Test1: { echo 'Run Test1' }, Test2: { echo 'Run Test2' } ) correctly uses parallel with keys and closures containing direct echo.
  3. Final Answer:

    parallel( Test1: { echo 'Run Test1' }, Test2: { echo 'Run Test2' } ) -> Option C
  4. Quick Check:

    parallel map with direct echo closures = parallel( Test1: { echo 'Run Test1' }, Test2: { echo 'Run Test2' } ) [OK]
Hint: parallel needs map keys with closures containing direct steps like echo [OK]
Common Mistakes:
  • Using stage inside parallel directly (wrong in scripted)
  • Adding steps block inside closures (declarative syntax mismatch)
  • Using braces incorrectly for parallel syntax
3. Given the following Jenkins scripted pipeline snippet, what will be the output?
parallel(
  TestA: {
    echo 'Running Test A'
  },
  TestB: {
    echo 'Running Test B'
  }
)
echo 'All tests done'
medium
A. Running Test A\nRunning Test B\nAll tests done
B. Running Test A\nAll tests done\nRunning Test B
C. All tests done\nRunning Test A\nRunning Test B
D. Running Test B\nRunning Test A\nAll tests done

Solution

  1. Step 1: Understand parallel execution output order

    Both TestA and TestB run at the same time, so their echo outputs appear before the next command.
  2. Step 2: Identify the sequence of echo commands

    After both parallel tasks finish, the final echo 'All tests done' runs.
  3. Final Answer:

    Running Test A\nRunning Test B\nAll tests done -> Option A
  4. Quick Check:

    Parallel tests output first, then final echo [OK]
Hint: Parallel echoes appear before next sequential echo [OK]
Common Mistakes:
  • Assuming output order is strictly sequential
  • Thinking 'All tests done' prints before tests
  • Confusing parallel output interleaving
4. You wrote this Jenkins pipeline snippet to run tests in parallel but it fails with a syntax error:
parallel(
  Test1: {
    stage('Test1') {
      steps {
        echo 'Running Test1'
      }
    }
  },
  Test2: {
    stage('Test2') {
      steps {
        echo 'Running Test2'
      }
    }
  }
)
What is the main cause of the error?
medium
A. Using parallel block outside a node block
B. Missing commas between parallel map entries
C. Incorrect indentation of the echo commands
D. Using stage and steps inside scripted pipeline closures

Solution

  1. Step 1: Identify pipeline type and syntax rules

    In scripted pipelines, stage and steps blocks are not used inside closures passed to parallel.
  2. Step 2: Recognize correct scripted pipeline parallel syntax

    Scripted pipelines use simple closures with commands like echo directly, without stage or steps.
  3. Final Answer:

    Using stage and steps inside scripted pipeline closures -> Option D
  4. Quick Check:

    Scripted parallel closures exclude stage/steps blocks [OK]
Hint: Scripted parallel closures don't use stage or steps blocks [OK]
Common Mistakes:
  • Mixing declarative syntax inside scripted pipeline
  • Forgetting commas between map entries (not the main error here)
  • Assuming indentation causes syntax errors
5. You want to run three test suites in parallel in a Jenkins declarative pipeline and fail the entire build if any test fails. Which snippet correctly achieves this?
hard
A. stages { stage('Parallel Tests') { parallel { Test1: { steps { sh 'run_test1.sh' } } Test2: { steps { sh 'run_test2.sh' } } Test3: { steps { sh 'run_test3.sh' } } } } }
B. parallel { stage('Test1') { steps { sh 'run_test1.sh' } } stage('Test2') { steps { sh 'run_test2.sh' } } stage('Test3') { steps { sh 'run_test3.sh' } } }
C. stages { parallel { stage('Test1') { steps { sh 'run_test1.sh' } } stage('Test2') { steps { sh 'run_test2.sh' } } stage('Test3') { steps { sh 'run_test3.sh' } } } }
D. stage('Parallel Tests') { parallel( Test1: { sh 'run_test1.sh' }, Test2: { sh 'run_test2.sh' }, Test3: { sh 'run_test3.sh' } ) }

Solution

  1. Step 1: Recall declarative pipeline structure for parallel stages

    Declarative pipelines require a stages block containing stage blocks; parallel tests go inside a single stage with a parallel block.
  2. Step 2: Identify correct syntax for parallel tests with failure propagation

    stages { stage('Parallel Tests') { parallel { Test1: { steps { sh 'run_test1.sh' } } Test2: { steps { sh 'run_test2.sh' } } Test3: { steps { sh 'run_test3.sh' } } } } } correctly uses stages block with a stage named 'Parallel Tests' containing a parallel block where each parallel branch is a closure with steps and sh commands. This is the proper declarative syntax and ensures the build fails if any test fails.
  3. Final Answer:

    stages { stage('Parallel Tests') { parallel { Test1: { steps { sh 'run_test1.sh' } } Test2: { steps { sh 'run_test2.sh' } } Test3: { steps { sh 'run_test3.sh' } } } } } -> Option A
  4. Quick Check:

    Declarative parallel inside a stage within stages block with steps closures [OK]
Hint: Use parallel inside a stage within stages block with steps closures [OK]
Common Mistakes:
  • Placing parallel outside stages block
  • Using parallel without wrapping in a stage
  • Mixing scripted and declarative syntax
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