0
0
Jenkinsdevops~10 mins

Library versioning in Jenkins - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Library versioning
Start Jenkins Pipeline
Load Library with Version
Use Library Functions
Execute Pipeline Steps
Pipeline Completes
The Jenkins pipeline starts, loads a specific library version, uses its functions, executes steps, and then completes.
Execution Sample
Jenkins
library('my-shared-lib@v1.2')
node {
  stage('Build') {
    mySharedLib.buildApp()
  }
}
This Jenkins pipeline loads version v1.2 of a shared library and calls its buildApp function inside a build stage.
Process Table
StepActionLibrary VersionFunction CalledPipeline State
1Start pipelinenonenonePipeline started
2Load libraryv1.2noneLibrary v1.2 loaded
3Enter node blockv1.2noneNode allocated
4Enter stage 'Build'v1.2noneStage Build started
5Call buildApp()v1.2buildAppbuildApp function executed
6Stage 'Build' completev1.2noneStage Build finished
7Pipeline completev1.2nonePipeline finished successfully
💡 Pipeline finishes after executing all stages using library version v1.2
Status Tracker
VariableStartAfter Step 2After Step 5Final
libraryVersionnonev1.2v1.2v1.2
pipelineStatenot startedstartedrunning buildAppfinished
Key Moments - 2 Insights
Why do we specify '@v1.2' when loading the library?
Specifying '@v1.2' tells Jenkins exactly which version of the library to use, ensuring consistent behavior as shown in execution_table step 2.
What happens if we omit the version when loading the library?
Jenkins uses the default or latest library version, which might cause unexpected changes. The execution_table shows explicit version loading to avoid this.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the library version loaded at step 2?
Alatest
Bv1.2
Cv1.0
Dnone
💡 Hint
Check the 'Library Version' column at step 2 in the execution_table.
At which step does the buildApp function get executed?
AStep 5
BStep 3
CStep 6
DStep 7
💡 Hint
Look at the 'Function Called' column in the execution_table.
If we change the library version to '@v2.0', what changes in the execution table?
APipeline state changes to failed
BFunction called changes to buildAppV2
CLibrary Version column shows v2.0 instead of v1.2
DNo changes at all
💡 Hint
Changing version affects the 'Library Version' column in the execution_table.
Concept Snapshot
Jenkins Library Versioning:
- Use library('name@version') to load specific library version.
- Ensures consistent pipeline behavior.
- Call library functions after loading.
- Version controls shared code updates.
- Avoids unexpected changes from default/latest versions.
Full Transcript
This visual execution shows how Jenkins pipelines load a specific version of a shared library using the syntax library('my-shared-lib@v1.2'). The pipeline starts, loads version v1.2 of the library, then calls the buildApp function from that library inside a build stage. The execution table tracks each step, showing the library version loaded and pipeline state changes. Key moments clarify why specifying the version is important to avoid unexpected behavior. The quiz tests understanding of version loading and function execution steps. The snapshot summarizes the key points about library versioning in Jenkins pipelines.