0
0
Jenkinsdevops~5 mins

Agent types (permanent, cloud) in Jenkins - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Agent types (permanent, cloud)
O(n)
Understanding Time 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.

Scenario Under Consideration

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.

Identify Repeating Operations

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.
How Execution Grows With Input

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)
10Permanent: 10 (agents always ready), Cloud: 10 (start each time)
100Permanent: 100, Cloud: 100
1000Permanent: 1000, Cloud: 1000

Pattern observation: Both scale linearly, but cloud agents add extra start time each time, making total time longer.

Final Time Complexity

Time Complexity: O(n)

This means the total time grows directly with the number of jobs or stages, whether using permanent or cloud agents.

Common Mistake

[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.

Interview Connect

Understanding how agent types affect job run time helps you design efficient pipelines and explain trade-offs clearly in real projects.

Self-Check

What if we reused cloud agents instead of starting new ones each time? How would the time complexity change?