Triggers directive in Jenkins - Time & Space Complexity
When using the triggers directive in Jenkins pipelines, it is important to understand how often the trigger checks run as the number of jobs grows.
We want to know how the time Jenkins spends checking triggers changes when we add more jobs or triggers.
Analyze the time complexity of the following Jenkins pipeline snippet using triggers.
pipeline {
triggers {
cron('H/15 * * * *')
}
stages {
stage('Build') {
steps {
echo 'Building...'
}
}
}
}
This pipeline uses a cron trigger to start the job every 15 minutes automatically.
Look for repeated checks or operations Jenkins performs related to triggers.
- Primary operation: Jenkins checks the cron schedule periodically to decide if the job should start.
- How many times: This check happens every minute for each job with a cron trigger configured.
As the number of jobs with triggers increases, Jenkins must check each trigger schedule regularly.
| Input Size (n jobs) | Approx. Operations per minute |
|---|---|
| 10 | 10 checks |
| 100 | 100 checks |
| 1000 | 1000 checks |
Pattern observation: The number of trigger checks grows linearly with the number of jobs.
Time Complexity: O(n)
This means the time Jenkins spends checking triggers grows directly in proportion to the number of jobs with triggers.
[X] Wrong: "Trigger checks happen only once regardless of job count."
[OK] Correct: Each job with a trigger requires its own schedule check, so more jobs mean more checks.
Understanding how trigger checks scale helps you design Jenkins setups that stay responsive as your projects grow.
"What if we added multiple triggers per job? How would that affect the time complexity?"