What is the primary purpose of configuring a global shared library in Jenkins?
Think about code reuse and pipeline consistency across jobs.
Global shared libraries allow Jenkins pipelines to reuse common code, making pipeline scripts cleaner and easier to maintain.
Which configuration step is required to add a global shared library in Jenkins?
Look for the global configuration section for pipeline libraries.
Global shared libraries are configured under Manage Jenkins > Configure System > Global Pipeline Libraries.
Given the following Jenkinsfile snippet using a global shared library:
library 'my-shared-lib'
pipeline {
agent any
stages {
stage('Example') {
steps {
script {
def util = new com.example.Util()
echo util.greet('World')
}
}
}
}
}If the greet method returns 'Hello, ' + name, what will be the output in the Jenkins console?
Check the string concatenation and spacing in the greet method.
The method returns 'Hello, ' plus the name, so the output includes a comma and space before 'World'.
A Jenkins pipeline fails with the error: java.lang.ClassNotFoundException: com.example.Util when trying to use a global shared library. What is the most likely cause?
Consider whether Jenkins knows about the shared library.
If Jenkins cannot find the class, it usually means the shared library is not configured or not loaded correctly.
Which approach is best for managing versions of a global shared library in Jenkins to ensure pipeline stability?
Think about how to control which code version pipelines use.
Using Git tags or branches and specifying the version in Jenkins ensures pipelines use tested library versions, improving stability.