Skip to content

[JENKINS-66036] Timeout option works inconsistent when applied on pipeline level vs on stage level #1451

@jenkins-infra-bot

Description

@jenkins-infra-bot

The timeout option works inconsistent when is defined on pipeline level vs on stage level. On pipeline level it is applied after allocating the node. On stage level it is applied ASAP. It causes a problems on heavy loaded environments when the builds wait quite long for an agent.

Pipeline Level:

pipeline {
    agent {
label 'tiny'
    }
    options {
// too short to get an agent
timeout(time: 1, activity: false, unit: 'SECONDS')
    }
    stages {
stage('Test') {
    steps {
echo 'success'
    }
}
    }
}

Output:

14:49:59  [Pipeline] Start of Pipeline
14:50:00  [Pipeline] node
14:50:10  Agent zjs-tiny-912zg is provisioned from template zjs-tiny
14:50:11  Running on zjs-tiny-912zg in /var/lib/jenkins/workspace/test
14:50:11  [Pipeline] {
14:50:11  [Pipeline] timeout
14:50:11  Timeout set to expire in 1 sec
14:50:11  [Pipeline] {
14:50:11  [Pipeline] stage
14:50:11  [Pipeline] { (Test)
14:50:11  [Pipeline] echo
14:50:11  success
14:50:11  [Pipeline] }
14:50:11  [Pipeline] // stage
14:50:11  [Pipeline] }
14:50:11  [Pipeline] // timeout
14:50:11  [Pipeline] }
14:50:11  [Pipeline] // node
14:50:11  [Pipeline] End of Pipeline
14:50:11  Finished: SUCCESS

Stage Level:

pipeline {
    agent none
    stages {
stage('Test') {
    agent {
label 'tiny'
    }
    options {
// too short to get an agent
timeout(time: 1, activity: false, unit: 'SECONDS')
    }
    steps {
echo 'success'
    }
}
    }
}

Output:

14:52:08  [Pipeline] Start of Pipeline
14:52:08  [Pipeline] stage
14:52:08  [Pipeline] { (Test)
14:52:08  [Pipeline] timeout
14:52:08  Timeout set to expire in 1 sec
14:52:08  [Pipeline] {
14:52:09  [Pipeline] node
14:52:09  Cancelling nested steps due to timeout
14:52:09  [Pipeline] // node
14:52:09  [Pipeline] }
14:52:09  [Pipeline] // timeout
14:52:10  [Pipeline] }
14:52:10  [Pipeline] // stage
14:52:10  [Pipeline] End of Pipeline
14:52:10  Timeout has been exceeded
14:52:10  Finished: ABORTED


Originally reported by agabrys, imported from: Timeout option works inconsistent when applied on pipeline level vs on stage level
  • status: Open
  • priority: Minor
  • component(s): pipeline-model-definition-plugin, workflow-basic-steps-plugin
  • resolution: Unresolved
  • votes: 0
  • watchers: 1
  • imported: 2025-12-06
Raw content of original issue

The timeout option works inconsistent when is defined on pipeline level vs on stage level. On pipeline level it is applied after allocating the node. On stage level it is applied ASAP. It causes a problems on heavy loaded environments when the builds wait quite long for an agent.

Pipeline Level:

pipeline {
    agent {
        label 'tiny'
    }
    options {
        // too short to get an agent
        timeout(time: 1, activity: false, unit: 'SECONDS')
    }
    stages {
        stage('Test') {
            steps {
                echo 'success'
            }
        }
    }
}

Output:

14:49:59  [Pipeline] Start of Pipeline
14:50:00  [Pipeline] node
14:50:10  Agent zjs-tiny-912zg is provisioned from template zjs-tiny
14:50:11  Running on zjs-tiny-912zg in /var/lib/jenkins/workspace/test
14:50:11  [Pipeline] {
14:50:11  [Pipeline] timeout
14:50:11  Timeout set to expire in 1 sec
14:50:11  [Pipeline] {
14:50:11  [Pipeline] stage
14:50:11  [Pipeline] { (Test)
14:50:11  [Pipeline] echo
14:50:11  success
14:50:11  [Pipeline] }
14:50:11  [Pipeline] // stage
14:50:11  [Pipeline] }
14:50:11  [Pipeline] // timeout
14:50:11  [Pipeline] }
14:50:11  [Pipeline] // node
14:50:11  [Pipeline] End of Pipeline
14:50:11  Finished: SUCCESS

Stage Level:

pipeline {
    agent none
    stages {
        stage('Test') {
            agent {
                label 'tiny'
            }
            options {
                // too short to get an agent
                timeout(time: 1, activity: false, unit: 'SECONDS')
            }
            steps {
                echo 'success'
            }
        }
    }
}

Output:

14:52:08  [Pipeline] Start of Pipeline
14:52:08  [Pipeline] stage
14:52:08  [Pipeline] { (Test)
14:52:08  [Pipeline] timeout
14:52:08  Timeout set to expire in 1 sec
14:52:08  [Pipeline] {
14:52:09  [Pipeline] node
14:52:09  Cancelling nested steps due to timeout
14:52:09  [Pipeline] // node
14:52:09  [Pipeline] }
14:52:09  [Pipeline] // timeout
14:52:10  [Pipeline] }
14:52:10  [Pipeline] // stage
14:52:10  [Pipeline] End of Pipeline
14:52:10  Timeout has been exceeded
14:52:10  Finished: ABORTED
environment
- Jenkins 2.289.2<br/>
- Pipeline: Declarative 1.8.5<br/>
- Pipeline: Basic Steps 2.23

Metadata

Metadata

Assignees

No one assigned

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions