0
0
Jenkinsdevops~5 mins

Stash and unstash for passing data in Jenkins - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Stash and unstash for passing data
O(n)
Understanding Time Complexity

We want to understand how the time to stash and unstash data changes as the amount of data grows.

How does Jenkins handle passing files between pipeline stages as data size increases?

Scenario Under Consideration

Analyze the time complexity of the following Jenkins pipeline snippet.


    stage('Build') {
      steps {
        sh 'make build'
        stash name: 'app', includes: '**/target/**'
      }
    }

    stage('Test') {
      steps {
        unstash 'app'
        sh 'make test'
      }
    }
    

This code builds the app, saves the build files with stash, then retrieves them with unstash for testing.

Identify Repeating Operations

Look for repeated actions that affect time.

  • Primary operation: Stashing and unstashing files involves copying files to and from the Jenkins master.
  • How many times: Each stash and unstash runs once per pipeline execution, but the time depends on the number and size of files.
How Execution Grows With Input

As the number or size of files grows, the time to stash and unstash grows roughly in proportion.

Input Size (files or total size)Approx. Operations (file copy time)
10 small filesLow time, quick copy
100 files or larger sizeAbout 10 times longer
1000 files or very large sizeMuch longer, roughly 100 times more work

Pattern observation: Time grows roughly linearly with the amount of data being stashed or unstashed.

Final Time Complexity

Time Complexity: O(n)

This means the time to stash and unstash grows directly with the number and size of files involved.

Common Mistake

[X] Wrong: "Stash and unstash time stays the same no matter how many files we pass."

[OK] Correct: More files or bigger files take more time to copy, so time grows with data size.

Interview Connect

Understanding how data passing scales helps you design efficient pipelines and explain trade-offs clearly.

Self-Check

"What if we compressed files before stashing? How would that affect the time complexity?"