0
0
Jenkinsdevops~5 mins

Email notifications in pipelines in Jenkins - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Email notifications in pipelines
O(n)
Understanding Time 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?

Scenario Under Consideration

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.

Identify Repeating Operations

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

As the number of stages increases, the total email sends increase linearly.

Input Size (number of stages)Approx. Email Sends
1010 emails
100100 emails
10001000 emails

Pattern observation: Doubling the number of stages doubles the number of emails sent.

Final Time Complexity

Time Complexity: O(n)

This means the time to send notifications grows directly in proportion to the number of stages.

Common Mistake

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

Interview Connect

Understanding how notification steps scale helps you design efficient pipelines that keep teams informed without slowing down the process too much.

Self-Check

"What if we send one email after all stages instead of after each stage? How would the time complexity change?"