Docker Pipeline plugin in Jenkins - Time & Space 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?
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.
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.
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) |
|---|---|
| 1 | 1 container start + 1 container stop |
| 10 | 10 container starts + 10 container stops |
| 100 | 100 container starts + 100 container stops |
Pattern observation: Each additional container run adds a fixed amount of work, so time grows linearly.
Time Complexity: O(n)
This means the total time grows linearly with the number of Docker container runs in the pipeline.
[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.
Understanding how pipeline steps scale with input helps you design efficient CI/CD workflows and explain your reasoning clearly in interviews.
"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?"