What is the main purpose of using the @Library annotation in a Jenkins pipeline script?
Think about how Jenkins pipelines reuse code across multiple jobs.
The @Library annotation is used to load shared libraries, which contain reusable pipeline code, into the current Jenkins pipeline script.
Given the Jenkins pipeline snippet below, what will be the effect of the @Library annotation?
@Library('utils@v1.2') _
node {
echo 'Running pipeline'
}Consider how versioning works with shared libraries in Jenkins.
The syntax @Library('utils@v1.2') loads the shared library named 'utils' at the specific version 'v1.2'.
Which of the following Jenkins pipeline snippets correctly loads two shared libraries named 'libA' and 'libB' using the @Library annotation?
Check the syntax for loading multiple libraries with optional versions.
The correct syntax to load multiple libraries with optional versions is using a list inside @Library, like @Library(['libA@1.0', 'libB@2.0']).
A Jenkins pipeline uses @Library('commonLib') but fails with the error: Library 'commonLib' not found. What is the most likely cause?
Think about where Jenkins looks for shared libraries.
Jenkins requires shared libraries to be configured globally in the Jenkins system configuration before they can be loaded with @Library.
Which practice is best when using the @Library annotation to ensure pipeline stability and reproducibility?
Consider how to avoid unexpected changes breaking your pipelines.
Specifying a fixed version or branch in @Library ensures that pipelines use a known stable version of the shared library, improving stability and reproducibility.