Email notifications in pipelines in Jenkins - Time & Space Complexity
We want to understand how the time to send email notifications changes as the number of pipeline stages or recipients grows.
How does adding more emails or stages affect the total time spent sending notifications?
Analyze the time complexity of the following Jenkins pipeline snippet that sends emails after each stage.
pipeline {
agent any
stages {
stage('Build') {
steps {
// build steps
emailext to: 'team@example.com', subject: 'Build Complete', body: 'Build finished'
}
}
stage('Test') {
steps {
// test steps
emailext to: 'team@example.com', subject: 'Test Complete', body: 'Tests finished'
}
}
}
}
This pipeline sends an email notification after each stage completes.
Look for repeated actions that take time.
- Primary operation: Sending an email notification after each stage.
- How many times: Once per stage, so the number of emails equals the number of stages.
As the number of stages increases, the total email sends increase linearly.
| Input Size (number of stages) | Approx. Email Sends |
|---|---|
| 10 | 10 emails |
| 100 | 100 emails |
| 1000 | 1000 emails |
Pattern observation: Doubling the number of stages doubles the number of emails sent.
Time Complexity: O(n)
This means the time to send notifications grows directly in proportion to the number of stages.
[X] Wrong: "Sending multiple emails at once takes the same time as sending one email."
[OK] Correct: Each email requires its own sending process, so more emails mean more total time.
Understanding how notification steps scale helps you design efficient pipelines that keep teams informed without slowing down the process too much.
"What if we send one email after all stages instead of after each stage? How would the time complexity change?"