Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-66036

Timeout option works inconsistent when applied on pipeline level vs on stage level

    XMLWordPrintable

Details

    Description

      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
      

      Attachments

        Activity

          agabrys Adam Gabryś created issue -
          agabrys Adam Gabryś made changes -
          Field Original Value New Value
          Description 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:
          {code}
          pipeline {
              agent {
                  label 'tiny'
              }
              options {
                  // too short to get an agent
                  timeout(time: 1, activity: false, unit: 'SECONDS')
              }
              stages {
                  stage('Test') {
                      steps {
                          echo 'success'
                      }
                  }
              }
          }
          {code}
          Output:
          {noformat}
          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
          {noformat}

          {code}
          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'
                      }
                  }
              }
          }
          {code}
          Output:
          {noformat}
          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
          {noformat}
          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:
          {code}
          pipeline {
              agent {
                  label 'tiny'
              }
              options {
                  // too short to get an agent
                  timeout(time: 1, activity: false, unit: 'SECONDS')
              }
              stages {
                  stage('Test') {
                      steps {
                          echo 'success'
                      }
                  }
              }
          }
          {code}
          Output:
          {noformat}
          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
          {noformat}

          Stage Level:
          {code}
          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'
                      }
                  }
              }
          }
          {code}
          Output:
          {noformat}
          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
          {noformat}

          People

            Unassigned Unassigned
            agabrys Adam Gabryś
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: