0
0
Jenkinsdevops~5 mins

Global shared library configuration in Jenkins - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Global shared library configuration
O(n)
Understanding Time Complexity

When Jenkins loads a global shared library, it runs code to make the library available to all pipelines.

We want to understand how the time to load this library changes as the library grows.

Scenario Under Consideration

Analyze the time complexity of this Jenkins global shared library loading snippet.


@Library('my-shared-lib') _

pipeline {
  agent any
  stages {
    stage('Example') {
      steps {
        script {
          mySharedFunction()
        }
      }
    }
  }
}
    

This code loads a shared library named 'my-shared-lib' and calls a function from it in a pipeline.

Identify Repeating Operations

Look for repeated actions when Jenkins loads the shared library.

  • Primary operation: Reading and parsing each Groovy script file in the library.
  • How many times: Once per file in the library, for all files in vars/, src/, and resources/ folders.
How Execution Grows With Input

As the number of files in the shared library increases, Jenkins must read and parse more files.

Input Size (number of files)Approx. Operations (file reads/parses)
1010
100100
10001000

Pattern observation: The time grows directly with the number of files to load.

Final Time Complexity

Time Complexity: O(n)

This means the loading time increases in a straight line as the library size grows.

Common Mistake

[X] Wrong: "Loading the shared library takes the same time no matter how big it is."

[OK] Correct: Jenkins must read and parse every file, so more files mean more work and longer load time.

Interview Connect

Understanding how Jenkins handles shared libraries helps you explain pipeline performance and scaling in real projects.

Self-Check

"What if the shared library used caching to avoid reloading unchanged files? How would that affect the time complexity?"