0
0
Jenkinsdevops~20 mins

Loading libraries in Jenkinsfile - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Shared Library Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of loading a shared library in Jenkinsfile?
Given this Jenkinsfile snippet:
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()
}
AmyFunction
BHello from library!
CError: myFunction not found
Dnull
Attempts:
2 left
💡 Hint
The shared library loads functions that can be called directly in the Jenkinsfile.
Configuration
intermediate
2: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?
Alibrary('utils@1.2.3')
Blibrary(name: 'utils', version: '1.2.3')
Clibrary('utils', '1.2.3')
DloadLibrary('utils', '1.2.3')
Attempts:
2 left
💡 Hint
The version is specified after an @ symbol in the library name string.
Troubleshoot
advanced
2:00remaining
Why does Jenkins fail to find the shared library function?
Given this Jenkinsfile:
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?
AThe shared library is not configured in Jenkins global settings.
BThe shared library version is missing in the library call.
CThe function greet is not defined as a global variable in vars directory.
DThe Jenkinsfile syntax for calling greet() is incorrect; it needs a prefix.
Attempts:
2 left
💡 Hint
Shared library functions must be in the vars directory to be called directly.
🔀 Workflow
advanced
2: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
A4,2,3,1
B2,3,4,1
C4,3,2,1
D2,4,3,1
Attempts:
2 left
💡 Hint
Think about creating the library first, then configuring Jenkins, then loading and using it.
Best Practice
expert
2: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?
ADo not specify versions and rely on Jenkins global default library version.
BAlways use the latest library version by calling library('lib@master') in Jenkinsfile.
CUpdate the shared library directly in Jenkins global config without version control.
DUse fixed library versions in Jenkinsfile and test updates in a separate branch before upgrading.
Attempts:
2 left
💡 Hint
Controlling versions and testing before upgrading helps avoid surprises.