Why should you create reusable pipeline steps in Jenkins pipelines?
Think about how repeating code affects maintenance.
Reusable steps help avoid code duplication, making pipelines simpler and easier to update.
Given this Jenkinsfile snippet calling a shared library step buildApp(), what will be the output?
pipeline {
agent any
stages {
stage('Build') {
steps {
script {
buildApp()
}
}
}
}
}
// Assume buildApp() prints 'Building application...'
Shared library steps are reusable functions defined outside the Jenkinsfile.
If the shared library is properly loaded, calling buildApp() runs its code and prints the message.
Which of the following is the correct way to define a reusable step named deployApp in a Jenkins shared library?
Shared library steps are usually Groovy methods starting with def.
In Jenkins shared libraries, reusable steps are defined as Groovy methods using def.
Given these reusable steps called in order: checkoutCode(), buildApp(), testApp(), what is the correct order of execution in the pipeline?
Think about the logical order: get code, build, then test.
The pipeline must first checkout code, then build it, and finally run tests.
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?
Check if the shared library is declared in the pipeline or global configuration.
This error usually means Jenkins cannot find the step because the shared library is not loaded or referenced correctly.