Challenge - 5 Problems
Shared Library Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
What is the output of loading a shared library in Jenkinsfile?
Given this Jenkinsfile snippet:
Assuming
library('my-shared-lib')
node {
echo myFunction()
}Assuming
myFunction returns 'Hello from library!', what will Jenkins print?Jenkins
library('my-shared-lib') node { echo myFunction() }
Attempts:
2 left
💡 Hint
The shared library loads functions that can be called directly in the Jenkinsfile.
✗ Incorrect
The
library step loads the shared library, making myFunction available. Calling it returns the string it defines.❓ Configuration
intermediate2:00remaining
Which syntax correctly loads a shared library with a specific version in Jenkinsfile?
You want to load the shared library named
utils at version 1.2.3. Which Jenkinsfile syntax is correct?Attempts:
2 left
💡 Hint
The version is specified after an @ symbol in the library name string.
✗ Incorrect
The correct syntax to load a specific version is
library('name@version'). Other options are invalid or do not exist.❓ Troubleshoot
advanced2:00remaining
Why does Jenkins fail to find the shared library function?
Given this Jenkinsfile:
And the shared library
Jenkins throws an error:
What is the most likely cause?
library('common-lib')
node {
echo greet()
}And the shared library
common-lib has a function greet defined in vars/greet.groovy.Jenkins throws an error:
groovy.lang.MissingMethodException: No signature of method: greet().What is the most likely cause?
Attempts:
2 left
💡 Hint
Shared library functions must be in the vars directory to be called directly.
✗ Incorrect
Functions in shared libraries must be placed in the vars directory as Groovy scripts to be accessible as global functions. If not, Jenkins cannot find them.
🔀 Workflow
advanced2:00remaining
What is the correct order to load and use a shared library in a Jenkins pipeline?
Arrange these steps in the correct order to use a shared library function in a Jenkinsfile:
1. Call the shared library function
2. Define the shared library in Jenkins global configuration
3. Load the shared library in Jenkinsfile
4. Create the shared library repository with functions
1. Call the shared library function
2. Define the shared library in Jenkins global configuration
3. Load the shared library in Jenkinsfile
4. Create the shared library repository with functions
Attempts:
2 left
💡 Hint
Think about creating the library first, then configuring Jenkins, then loading and using it.
✗ Incorrect
First, create the library repo with functions. Then configure Jenkins to know about it. Then load it in Jenkinsfile. Finally, call its functions.
✅ Best Practice
expert2:00remaining
Which approach is best to ensure shared library updates do not break Jenkins pipelines?
You maintain multiple Jenkins pipelines using a shared library. How do you best manage library updates to avoid breaking pipelines?
Attempts:
2 left
💡 Hint
Controlling versions and testing before upgrading helps avoid surprises.
✗ Incorrect
Using fixed versions and testing updates in branches prevents unexpected breakage in pipelines when library code changes.