0
0
Jenkinsdevops~5 mins

Archiving artifacts in Jenkins - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Archiving artifacts
O(n)
Understanding Time Complexity

When Jenkins archives artifacts, it saves files from a build for later use. Understanding how the time to archive grows helps us plan for bigger projects.

We want to know: how does archiving time change as the number of files or their size increases?

Scenario Under Consideration

Analyze the time complexity of the following Jenkins pipeline snippet.


pipeline {
  agent any
  stages {
    stage('Build') {
      steps {
        // build steps here
      }
    }
    stage('Archive') {
      steps {
        archiveArtifacts artifacts: '**/target/*.jar', fingerprint: true
      }
    }
  }
}
    

This code archives all .jar files found under any target folder after the build finishes.

Identify Repeating Operations

Look for repeated actions that affect time.

  • Primary operation: Scanning the workspace to find matching files and copying each file to the archive storage.
  • How many times: Once per file found matching the pattern; each file is processed individually.
How Execution Grows With Input

As the number of files grows, the time to archive grows too.

Input Size (n files)Approx. Operations
10About 10 file scans and copies
100About 100 file scans and copies
1000About 1000 file scans and copies

Pattern observation: The time grows roughly in direct proportion to the number of files.

Final Time Complexity

Time Complexity: O(n)

This means if you double the number of files, the archiving time roughly doubles too.

Common Mistake

[X] Wrong: "Archiving time stays the same no matter how many files there are."

[OK] Correct: Each file must be found and copied, so more files mean more work and more time.

Interview Connect

Knowing how archiving scales helps you understand build pipelines better. It shows you how tasks grow with project size, a useful skill in real DevOps work.

Self-Check

"What if we changed the archive pattern to include subfolders with many files? How would the time complexity change?"