0
0
Jenkinsdevops~5 mins

Failing builds on test failures in Jenkins - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Failing builds on test failures
O(n)
Understanding Time Complexity

We want to understand how the time to run a Jenkins build changes when tests are involved.

Specifically, how does the build time grow as the number of tests increases?

Scenario Under Consideration

Analyze the time complexity of the following Jenkins pipeline snippet.

pipeline {
  agent any
  stages {
    stage('Test') {
      steps {
        script {
          def testResults = runTests() // runs all tests
          if (testResults.hasFailures()) {
            error('Tests failed, stopping build')
          }
        }
      }
    }
  }
}

This code runs a set of tests and fails the build if any test fails.

Identify Repeating Operations

Look for repeated actions that take time.

  • Primary operation: Running each test in the test suite.
  • How many times: Once per test, repeated for all tests.
How Execution Grows With Input

As the number of tests grows, the time to run them grows too.

Input Size (n)Approx. Operations
10Runs 10 tests
100Runs 100 tests
1000Runs 1000 tests

Pattern observation: The time grows roughly in direct proportion to the number of tests.

Final Time Complexity

Time Complexity: O(n)

This means the build time increases linearly as the number of tests increases.

Common Mistake

[X] Wrong: "Failing early on the first test failure makes the build time constant regardless of test count."

[OK] Correct: Even if the build stops early, in the worst case all tests run before failure, so time still grows with test count.

Interview Connect

Understanding how test execution time affects build time helps you design efficient pipelines and explain build performance clearly.

Self-Check

What if we parallelize running tests? How would the time complexity change?