0
0
Jenkinsdevops~20 mins

@Library annotation in Jenkins - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Shared Library Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Purpose of @Library Annotation in Jenkins

What is the main purpose of using the @Library annotation in a Jenkins pipeline script?

ATo import shared pipeline code from a shared library repository into the current pipeline.
BTo declare environment variables for the pipeline execution.
CTo define the stages of the pipeline in a declarative syntax.
DTo specify the Jenkins agent where the pipeline should run.
Attempts:
2 left
💡 Hint

Think about how Jenkins pipelines reuse code across multiple jobs.

💻 Command Output
intermediate
2:00remaining
Output of Using @Library Annotation with Version

Given the Jenkins pipeline snippet below, what will be the effect of the @Library annotation?

@Library('utils@v1.2') _
node {
  echo 'Running pipeline'
}
AIt loads the latest version of the 'utils' library ignoring the version 'v1.2'.
BIt loads the 'utils' shared library at version 'v1.2' for use in the pipeline.
CIt sets the pipeline to run only on nodes labeled 'v1.2'.
DIt causes a syntax error because versioning is not supported in @Library.
Attempts:
2 left
💡 Hint

Consider how versioning works with shared libraries in Jenkins.

Configuration
advanced
2:30remaining
Correct Syntax to Load Multiple Shared Libraries

Which of the following Jenkins pipeline snippets correctly loads two shared libraries named 'libA' and 'libB' using the @Library annotation?

A
@Library('libA')
@Library('libB') _
node {
  echo 'Libraries loaded'
}
B
@Library(['libA', 'libB']) _
node {
  echo 'Libraries loaded'
}
C
@Library('libA,libB') _
node {
  echo 'Libraries loaded'
}
D
@Library(['libA@1.0', 'libB@2.0']) _
node {
  echo 'Libraries loaded'
}
Attempts:
2 left
💡 Hint

Check the syntax for loading multiple libraries with optional versions.

Troubleshoot
advanced
2:30remaining
Troubleshooting @Library Annotation Loading Failure

A Jenkins pipeline uses @Library('commonLib') but fails with the error: Library 'commonLib' not found. What is the most likely cause?

AThe Jenkins agent does not have internet access.
BThe pipeline script has a syntax error unrelated to the library.
CThe shared library 'commonLib' is not configured in Jenkins global settings.
DThe <code>@Library</code> annotation must be placed inside the <code>node</code> block.
Attempts:
2 left
💡 Hint

Think about where Jenkins looks for shared libraries.

Best Practice
expert
3:00remaining
Best Practice for Versioning Shared Libraries with @Library

Which practice is best when using the @Library annotation to ensure pipeline stability and reproducibility?

AAlways specify a fixed version or branch in the <code>@Library</code> annotation instead of using the default branch.
BUse the default branch without specifying a version to always get the latest updates.
CLoad shared libraries dynamically inside pipeline steps instead of using <code>@Library</code> annotation.
DAvoid using shared libraries and duplicate code in each pipeline for clarity.
Attempts:
2 left
💡 Hint

Consider how to avoid unexpected changes breaking your pipelines.