0
0
Jenkinsdevops~20 mins

Parallel stages execution in Jenkins - Practice Problems & Coding Challenges

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