0
0
Jenkinsdevops~5 mins

Custom notification logic in Jenkins - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Custom notification logic
O(n)
Understanding Time Complexity

When Jenkins sends notifications based on build results, it runs some code to decide who to notify.

We want to know how the time it takes grows as the number of recipients or conditions increases.

Scenario Under Consideration

Analyze the time complexity of the following Jenkins pipeline snippet.


pipeline {
  agent any
  stages {
    stage('Notify') {
      steps {
        script {
          def users = ['alice', 'bob', 'carol', 'dave']
          users.each { user ->
            if (user.startsWith('a') || user.startsWith('b')) {
              echo "Notify ${user}"
            }
          }
        }
      }
    }
  }
}
    

This code loops through a list of users and sends notifications only to those whose names start with 'a' or 'b'.

Identify Repeating Operations

Identify the loops, recursion, array traversals that repeat.

  • Primary operation: Looping through the list of users with each.
  • How many times: Once for each user in the list.
How Execution Grows With Input

As the number of users grows, the code checks each user once.

Input Size (n)Approx. Operations
1010 checks
100100 checks
10001000 checks

Pattern observation: The number of operations grows directly with the number of users.

Final Time Complexity

Time Complexity: O(n)

This means the time to run the notification logic grows in a straight line as the user list gets bigger.

Common Mistake

[X] Wrong: "The notification time stays the same no matter how many users there are."

[OK] Correct: Because the code checks each user one by one, more users mean more checks and more time.

Interview Connect

Understanding how loops affect time helps you explain how your code scales in real projects.

Self-Check

"What if we added nested loops to notify users based on multiple conditions? How would the time complexity change?"