0
0
Jenkinsdevops~20 mins

Why scripted pipelines offer flexibility in Jenkins - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Scripted Pipeline Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Why do scripted pipelines allow more complex logic than declarative pipelines?

Choose the best reason why scripted pipelines in Jenkins offer more flexibility compared to declarative pipelines.

AScripted pipelines automatically generate UI forms for input parameters.
BScripted pipelines have a simpler syntax that restricts complex logic.
CDeclarative pipelines allow more customization than scripted pipelines.
DScripted pipelines use Groovy code, allowing loops, conditionals, and custom functions.
Attempts:
2 left
💡 Hint

Think about what programming features Groovy code provides.

💻 Command Output
intermediate
2:00remaining
Output of a scripted pipeline with conditional stage execution

What will be the output of this scripted pipeline snippet when the variable runTests is false?

Jenkins
def runTests = false
node {
  stage('Build') {
    echo 'Building...'
  }
  if (runTests) {
    stage('Test') {
      echo 'Testing...'
    }
  }
  stage('Deploy') {
    echo 'Deploying...'
  }
}
ABuild stage skipped; only Deploying...
BBuilding...\nTesting...\nDeploying...
CBuilding...\nDeploying...
DTesting...\nDeploying...
Attempts:
2 left
💡 Hint

Check the condition controlling the 'Test' stage.

🔀 Workflow
advanced
2:00remaining
How to implement parallel stages in a scripted pipeline

Which scripted pipeline code correctly runs two stages in parallel?

Aparallel firstBranch: { echo 'Running first branch' }, secondBranch: { echo 'Running second branch' }
Bstage('Parallel') { runInParallel { echo 'First'; echo 'Second' } }
Cparallel { stage('First') { echo 'First' } stage('Second') { echo 'Second' } }
Dnode { parallel { echo 'First'; echo 'Second' } }
Attempts:
2 left
💡 Hint

Remember the syntax for the parallel step in scripted pipelines.

Troubleshoot
advanced
2:00remaining
Why does this scripted pipeline fail with a missing method error?

Given this scripted pipeline snippet, why does Jenkins report groovy.lang.MissingMethodException?

Jenkins
node {
  stage('Example') {
    sh 'echo Hello'
  }
  stage('Example') {
    sh 'echo World'
  }
}
ADuplicate stage names cause Jenkins to fail with a missing method error.
BThe <code>sh</code> step is not allowed inside scripted pipelines.
CStages must be inside a <code>pipeline</code> block in scripted pipelines.
DThe <code>node</code> block is missing a required parameter.
Attempts:
2 left
💡 Hint

Check the stage names and how Jenkins handles them.

Best Practice
expert
2:00remaining
Best practice for sharing variables between stages in scripted pipelines

In a scripted pipeline, what is the best way to share a variable's value between multiple stages?

ADeclare the variable outside the <code>node</code> block as a global variable.
BUse <code>env</code> environment variables to store and share values.
CDeclare the variable inside each stage separately to avoid conflicts.
DUse <code>def</code> inside each stage to create local copies.
Attempts:
2 left
💡 Hint

Think about persistence and accessibility of variables across stages.