0
0
Jenkinsdevops~5 mins

@Library annotation in Jenkins - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the @Library annotation in Jenkins pipelines?
The @Library annotation is used to load shared libraries into a Jenkins pipeline script, allowing reuse of common code across multiple pipelines.
Click to reveal answer
beginner
How do you specify a shared library named utils using the @Library annotation?
You write @Library('utils') _ at the top of your Jenkins pipeline script to load the utils shared library.
Click to reveal answer
intermediate
What does the underscore _ mean after the @Library annotation?
The underscore <code>_</code> tells Jenkins to import the library into the script's namespace so you can use its functions and classes directly.
Click to reveal answer
intermediate
Can you load multiple shared libraries with @Library? How?
Yes, you can load multiple libraries by listing them separated by commas inside the annotation, like @Library(['lib1', 'lib2']) _.
Click to reveal answer
beginner
What happens if a shared library is not configured in Jenkins but you try to load it with @Library?
Jenkins will fail the pipeline with an error saying the library is not found because it must be configured in Jenkins global settings before use.
Click to reveal answer
What is the correct way to load a shared library named 'commonLib' in a Jenkins pipeline?
AloadLibrary('commonLib')
B@Library('commonLib') _
Cimport 'commonLib'
DuseLibrary('commonLib')
What does the underscore _ do after the @Library annotation?
AIt imports the library into the script namespace
BIt comments out the annotation
CIt runs the library code immediately
DIt declares a variable
How do you load multiple shared libraries in one annotation?
Aimport ['libA', 'libB']
B@Library('libA') @Library('libB')
CloadLibraries('libA', 'libB')
D@Library(['libA', 'libB']) _
Where must shared libraries be configured before using @Library?
AIn Jenkins global configuration under Shared Libraries
BIn the pipeline script itself
CIn the Jenkinsfile repository
DIn the Jenkins agent settings
What happens if you try to load a non-existent shared library with @Library?
AJenkins creates a new empty library
BPipeline ignores the library and continues
CPipeline fails with a library not found error
DPipeline runs but skips library functions
Explain how the @Library annotation works in Jenkins pipelines and why it is useful.
Think about how you share common code across projects.
You got /4 concepts.
    Describe the steps to use multiple shared libraries in a Jenkins pipeline using the @Library annotation.
    How do you load more than one library at once?
    You got /4 concepts.