0
0
Jenkinsdevops~5 mins

Hybrid CI/CD approaches in Jenkins - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Hybrid CI/CD approaches
O(n)
Understanding Time Complexity

We want to understand how the time to run a hybrid CI/CD pipeline changes as we add more projects or steps.

How does the pipeline's work grow when combining continuous integration and delivery tasks?

Scenario Under Consideration

Analyze the time complexity of the following Jenkins pipeline snippet.

pipeline {
  agent any
  stages {
    stage('Build') {
      steps {
        script {
          for (int i = 0; i < projects.size(); i++) {
            build job: projects[i], wait: true
          }
        }
      }
    }
    stage('Deploy') {
      steps {
        parallel projects.collectEntries { [(it): { deploy(it) }] }
      }
    }
  }
}

This pipeline builds multiple projects one after another, then deploys them all at the same time in parallel.

Identify Repeating Operations

Look at the loops and parallel tasks that repeat work.

  • Primary operation: Loop over projects to build sequentially, then parallel deploy.
  • How many times: Once per project for build, once per project for deploy.
How Execution Grows With Input

As the number of projects grows, the build time adds up, but deploy happens all at once.

Input Size (n)Approx. Operations
1010 builds + 1 parallel deploy
100100 builds + 1 parallel deploy
10001000 builds + 1 parallel deploy

Pattern observation: Build time grows linearly with projects; deploy time stays roughly constant due to parallelism.

Final Time Complexity

Time Complexity: O(n)

This means the total time grows directly with the number of projects because builds run one after another.

Common Mistake

[X] Wrong: "Because deploy is parallel, the whole pipeline runs in constant time regardless of projects."

[OK] Correct: The build stage is sequential and takes longer as projects increase, so total time still grows with project count.

Interview Connect

Understanding how sequential and parallel steps affect pipeline time helps you design efficient CI/CD workflows and explain your choices clearly.

Self-Check

What if we changed the build stage to run builds in parallel too? How would the time complexity change?