Docker agents for isolation in Jenkins - Time & Space Complexity
We want to understand how the time to run Jenkins jobs changes when using Docker agents for isolation.
Specifically, how does the number of jobs affect the total execution time?
Analyze the time complexity of the following Jenkins pipeline snippet using Docker agents.
pipeline {
agent none
stages {
stage('Build') {
agent {
docker {
image 'maven:3-alpine'
}
}
steps {
sh 'mvn clean install'
}
}
}
}
This pipeline runs a build stage inside a Docker container to isolate the environment.
Look for repeated actions that affect time.
- Primary operation: Starting a Docker container for each build stage.
- How many times: Once per build stage execution, repeated for each job run.
As the number of jobs increases, each job starts its own Docker container.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 jobs | 10 container startups + 10 builds |
| 100 jobs | 100 container startups + 100 builds |
| 1000 jobs | 1000 container startups + 1000 builds |
Pattern observation: The total time grows roughly linearly with the number of jobs because each job starts a container and runs the build.
Time Complexity: O(n)
This means the total execution time increases directly in proportion to the number of jobs run.
[X] Wrong: "Starting Docker containers is instant and does not affect total time."
[OK] Correct: Each container startup takes time, so as jobs increase, container startup time adds up and affects total execution time.
Understanding how container startup impacts job time shows you can think about real-world Jenkins pipeline performance and resource use.
"What if we reused a single Docker container for multiple jobs instead of starting a new one each time? How would the time complexity change?"