0
0
Jenkinsdevops~20 mins

Creating reusable pipeline steps in Jenkins - Practice Exercises

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Reusable Pipeline Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:00remaining
What is the main benefit of using reusable pipeline steps in Jenkins?

Why should you create reusable pipeline steps in Jenkins pipelines?

ATo increase the pipeline execution time by adding more steps
BTo avoid repeating the same code and make pipelines easier to maintain
CTo make the pipeline code more complex and harder to understand
DTo prevent the pipeline from running on multiple agents
Attempts:
2 left
💡 Hint

Think about how repeating code affects maintenance.

💻 Command Output
intermediate
1:30remaining
Output of calling a shared library step in Jenkins pipeline

Given this Jenkinsfile snippet calling a shared library step buildApp(), what will be the output?

Jenkins
pipeline {
  agent any
  stages {
    stage('Build') {
      steps {
        script {
          buildApp()
        }
      }
    }
  }
}

// Assume buildApp() prints 'Building application...'
ANo output, step is skipped
BError: buildApp() is not defined
CPipeline fails with syntax error
DBuilding application...
Attempts:
2 left
💡 Hint

Shared library steps are reusable functions defined outside the Jenkinsfile.

Configuration
advanced
2:00remaining
How to define a reusable step in a Jenkins shared library

Which of the following is the correct way to define a reusable step named deployApp in a Jenkins shared library?

Adef deployApp() { echo 'Deploying application...' }
Bstep deployApp { echo 'Deploying application...' }
Cfunction deployApp() { echo 'Deploying application...' }
DdeployApp() => { echo 'Deploying application...' }
Attempts:
2 left
💡 Hint

Shared library steps are usually Groovy methods starting with def.

🔀 Workflow
advanced
1:30remaining
Order of execution in a Jenkins pipeline using reusable steps

Given these reusable steps called in order: checkoutCode(), buildApp(), testApp(), what is the correct order of execution in the pipeline?

A2,1,3
B3,2,1
C1,2,3
D1,3,2
Attempts:
2 left
💡 Hint

Think about the logical order: get code, build, then test.

Troubleshoot
expert
2:30remaining
Why does calling a reusable step cause 'No such DSL method' error?

You have defined a reusable step deployApp() in your shared library, but Jenkins pipeline fails with No such DSL method 'deployApp'. What is the most likely cause?

AThe shared library is not properly loaded or configured in the pipeline
BThe deployApp() method has a syntax error inside its definition
CThe Jenkins agent does not have enough memory to run the step
DThe pipeline script is missing the <code>agent any</code> declaration
Attempts:
2 left
💡 Hint

Check if the shared library is declared in the pipeline or global configuration.