Agent types (permanent, cloud) in Jenkins - Time & Space Complexity
When Jenkins runs jobs, it uses agents to do the work. Different agent types affect how long it takes to start and run jobs.
We want to understand how the time to run jobs changes with the number of jobs and agent types.
Analyze the time complexity of this Jenkins pipeline using permanent and cloud agents.
pipeline {
agent none
stages {
stage('Build') {
agent { label 'permanent-agent' }
steps { echo 'Building on permanent agent' }
}
stage('Test') {
agent { label 'cloud-agent' }
steps { echo 'Testing on cloud agent' }
}
}
}
This pipeline runs two stages: one on a permanent agent and one on a cloud agent that starts on demand.
Look at what repeats when running multiple jobs or stages.
- Primary operation: Starting agents for each stage/job.
- How many times: Once per stage or job; permanent agents are always ready, cloud agents start each time.
As the number of jobs or stages (n) grows, the time to run them changes differently for each agent type.
| Input Size (n) | Approx. Operations (Agent Starts) |
|---|---|
| 10 | Permanent: 10 (agents always ready), Cloud: 10 (start each time) |
| 100 | Permanent: 100, Cloud: 100 |
| 1000 | Permanent: 1000, Cloud: 1000 |
Pattern observation: Both scale linearly, but cloud agents add extra start time each time, making total time longer.
Time Complexity: O(n)
This means the total time grows directly with the number of jobs or stages, whether using permanent or cloud agents.
[X] Wrong: "Cloud agents start instantly, so they don't add extra time compared to permanent agents."
[OK] Correct: Cloud agents need time to start up each time, so they add extra delay that grows with the number of jobs.
Understanding how agent types affect job run time helps you design efficient pipelines and explain trade-offs clearly in real projects.
What if we reused cloud agents instead of starting new ones each time? How would the time complexity change?