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?
✗ Incorrect
The
@Library('commonLib') _ annotation is the correct syntax to load a shared library in Jenkins pipelines.What does the underscore
_ do after the @Library annotation?✗ Incorrect
The underscore
_ imports the shared library so its functions and classes can be used in the pipeline script.How do you load multiple shared libraries in one annotation?
✗ Incorrect
You list multiple libraries inside an array in the annotation like
@Library(['libA', 'libB']) _.Where must shared libraries be configured before using
@Library?✗ Incorrect
Shared libraries must be configured in Jenkins global settings under Shared Libraries to be available for pipelines.
What happens if you try to load a non-existent shared library with
@Library?✗ Incorrect
Jenkins will fail the pipeline with an error because the library must exist and be configured before use.
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.