0
0
Jenkinsdevops~10 mins

Library directory structure in Jenkins - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Library directory structure
Start: Jenkins Pipeline
Load Shared Library
Look for vars/ directory
Look for src/ directory
Look for resources/ directory
Use library classes and vars in pipeline
Pipeline executes with shared code
Jenkins pipeline loads the shared library, then looks for specific directories (vars, src, resources) to find reusable code and resources for the pipeline execution.
Execution Sample
Jenkins
library('my-shared-lib')

pipeline {
  agent any
  stages {
    stage('Example') {
      steps { script { myFunction() } }
    }
  }
}
This Jenkins pipeline loads a shared library and calls a function defined in the library's vars directory.
Process Table
StepActionDirectory CheckedResultPipeline Effect
1Load shared library 'my-shared-lib'N/ALibrary loadedLibrary code available
2Check for vars/ directoryvars/FoundFunctions and vars available for pipeline
3Check for src/ directorysrc/FoundClasses available for pipeline
4Check for resources/ directoryresources/FoundStatic files available for pipeline
5Call myFunction() from vars/vars/myFunction.groovyExecutedStep runs in pipeline
6Pipeline completesN/ASuccessPipeline finished
7ExitN/ANo more stepsPipeline ends
💡 Pipeline ends after all stages complete successfully
Status Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4After Step 5Final
libraryLoadedfalsetruetruetruetruetruetrue
varsDirFoundfalsefalsetruetruetruetruetrue
srcDirFoundfalsefalsefalsetruetruetruetrue
resourcesDirFoundfalsefalsefalsefalsetruetruetrue
myFunctionCalledfalsefalsefalsefalsefalsetruetrue
pipelineStatusnot startedrunningrunningrunningrunningrunningsuccess
Key Moments - 2 Insights
Why does Jenkins check multiple directories like vars/, src/, and resources/ in the library?
Jenkins looks in these directories to find different types of reusable code and files: vars/ for simple functions, src/ for classes, and resources/ for static files. This is shown in steps 2, 3, and 4 of the execution table.
What happens if the vars/ directory is missing in the shared library?
If vars/ is missing, functions like myFunction() won't be found, causing pipeline errors when called. Step 2 in the execution table shows vars/ found; if missing, the pipeline would fail at step 5.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, at which step is the shared library first confirmed loaded?
AStep 2
BStep 5
CStep 1
DStep 7
💡 Hint
Check the 'Action' and 'Result' columns in the first row of the execution table.
According to the variable tracker, when does the variable 'myFunctionCalled' change to true?
AAfter Step 5
BAfter Step 4
CAfter Step 2
DAfter Step 7
💡 Hint
Look at the 'myFunctionCalled' row and see when it changes from false to true.
If the resources/ directory was missing, which step in the execution table would show a different result?
AStep 3
BStep 4
CStep 2
DStep 5
💡 Hint
Check the 'Directory Checked' and 'Result' columns for step 4.
Concept Snapshot
Jenkins shared libraries have a standard directory structure:
- vars/: simple Groovy scripts as functions
- src/: Groovy classes in packages
- resources/: static files like templates
Pipeline loads the library, then looks in these directories to find reusable code.
Functions in vars/ can be called directly in pipelines.
Classes in src/ require import or usage via @Library.
Full Transcript
This visual execution shows how Jenkins loads a shared library and checks its directory structure. First, the pipeline loads the library, confirming it is available. Then Jenkins looks for the vars/ directory to find simple functions, the src/ directory for classes, and the resources/ directory for static files. Each directory found makes its contents available to the pipeline. The pipeline then calls a function from vars/, which executes successfully. Variables track the state of loading and function calls. Key moments clarify why Jenkins checks multiple directories and what happens if one is missing. The quiz tests understanding of when the library is loaded, when functions are called, and the effect of missing directories.