0
0
Jenkinsdevops~5 mins

Loading libraries in Jenkinsfile - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of loading libraries in a Jenkinsfile?
Loading libraries in a Jenkinsfile allows you to reuse shared code and functions across multiple pipelines, making your Jenkinsfiles cleaner and easier to maintain.
Click to reveal answer
beginner
How do you load a shared library in a Jenkinsfile?
You use the @Library annotation followed by the library name, for example: @Library('my-shared-lib') _ at the top of your Jenkinsfile.
Click to reveal answer
intermediate
What does the underscore (_) mean after the @Library('lib-name') annotation?
The underscore tells Jenkins to import the library and make its classes and functions available in the Jenkinsfile.
Click to reveal answer
intermediate
Where do you configure shared libraries in Jenkins?
Shared libraries are configured in Jenkins under Manage Jenkins > Configure System > Global Pipeline Libraries. You define the library name, source code repository, and default version there.
Click to reveal answer
advanced
What is the difference between a global and a local library in Jenkins?
Global libraries are configured once in Jenkins and available to all pipelines. Local libraries are loaded from the same repository as the Jenkinsfile and are only available to that pipeline.
Click to reveal answer
How do you import a shared library named 'utils' in a Jenkinsfile?
A@Library('utils') _
Bimport 'utils'
CloadLibrary('utils')
DuseLibrary('utils')
Where do you set up the repository URL for a shared library in Jenkins?
AManage Jenkins > Configure System > Global Pipeline Libraries
BManage Jenkins > Manage Plugins
CPipeline script in Jenkinsfile
DManage Jenkins > System Information
What does the underscore (_) do after the @Library annotation?
AIt comments out the line
BIt imports the library into the Jenkinsfile
CIt defines a variable
DIt runs the library code immediately
Which of the following is NOT true about shared libraries in Jenkins?
AThey are configured globally in Jenkins
BThey help reuse code across pipelines
CThey can be versioned
DThey must be written in Groovy
What is a local library in Jenkins?
AA library that runs outside Jenkins
BA library configured globally in Jenkins
CA library loaded from the same repository as the Jenkinsfile
DA library downloaded from the internet
Explain how to load and use a shared library in a Jenkinsfile.
Think about the syntax and where you configure the library.
You got /4 concepts.
    Describe the difference between global and local libraries in Jenkins and when you might use each.
    Consider scope and reuse.
    You got /4 concepts.