0
0
Jenkinsdevops~5 mins

Docker Pipeline plugin in Jenkins - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Docker Pipeline plugin
O(n)
Understanding Time Complexity

We want to understand how the time taken by a Jenkins pipeline using the Docker Pipeline plugin changes as we add more steps or containers.

Specifically, how does the number of Docker operations affect the total execution time?

Scenario Under Consideration

Analyze the time complexity of the following Jenkins pipeline snippet using the Docker Pipeline plugin.

pipeline {
  agent any
  stages {
    stage('Build') {
      steps {
        script {
          docker.image('maven:3.6.3-jdk-11').inside {
            sh 'mvn clean install'
          }
        }
      }
    }
  }
}

This pipeline runs a Maven build inside a Docker container using the Docker Pipeline plugin.

Identify Repeating Operations

Look for repeated actions that take time.

  • Primary operation: Starting and stopping the Docker container for the build.
  • How many times: Once per pipeline run in this example, but could be multiple if repeated in loops or multiple stages.
How Execution Grows With Input

As the number of Docker container runs increases, the total time grows roughly in direct proportion.

Input Size (number of container runs)Approx. Operations (container start/stop)
11 container start + 1 container stop
1010 container starts + 10 container stops
100100 container starts + 100 container stops

Pattern observation: Each additional container run adds a fixed amount of work, so time grows linearly.

Final Time Complexity

Time Complexity: O(n)

This means the total time grows linearly with the number of Docker container runs in the pipeline.

Common Mistake

[X] Wrong: "Starting a Docker container inside the pipeline is instant and does not affect time much."

[OK] Correct: Starting and stopping containers takes noticeable time, so more container runs add up and increase total pipeline time.

Interview Connect

Understanding how pipeline steps scale with input helps you design efficient CI/CD workflows and explain your reasoning clearly in interviews.

Self-Check

"What if we reused a single Docker container for multiple build steps instead of starting a new one each time? How would the time complexity change?"