Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Timeout on a Build Step of Jenkins

In Jenkins, is there a way to give different timeouts to each or selected build step?
Build-time plugin out gives functionality of timeout "Abort the build if it's stuck" on complete project, what I need is to give different timeouts for each step. This way I can make my process more efficient.

like image 292
rohits Avatar asked Sep 02 '12 07:09

rohits


People also ask

How do I set Jenkins timeout?

Go to Manage Jenkins and then Configure System . Under the item Global Build Time Out you can activate a global timeout which will be applied to any job. Choose your timeout strategy, the duration and add actions which should be executed at timeout.

What is timeout in Jenkins pipeline?

The declarative Jenkins Pipeline allows us to define timeout either at the pipeline level or the specific stage. This feature prevents Jenkins's job from getting stuck. However, in some cases, we want to accept that one stage may timeout, but we want to keep the remaining stages running.

What is the default timeout for Jenkins?

Its default time is 10 minutes.

How does Jenkins pipeline increase timeout?

For a Declarative Pipeline it is adviced to use the timeout step in the options-section. Executes the code inside the block with a determined time out limit. If the time limit is reached, an exception (org. jenkinsci.


3 Answers

If you are using Jenkins pipeline, and the newer declarative style (has a top level pipeline { element) then there is a timeout option that can be used for the overall job, or on individual stages:

pipeline {
    agent any

    options {
        timeout(time: 1, unit: 'HOURS')   // timeout on whole pipeline job
    }

    stages {
        stage('Example') {
          options {
              timeout(time: 1, unit: 'HOURS')   // timeout on this stage
          }
          steps {
              echo 'Hello World'
          }
        }
    }
}

Docs: https://jenkins.io/doc/book/pipeline/syntax/#options

like image 163
Chris R Avatar answered Oct 06 '22 11:10

Chris R


As of current versions of Jenkins, this can be done. Hit 'Configure', then select the 'Build Environment' tab, and then set your timeout.

Here's an screenshot: enter image description here

like image 41
JESii Avatar answered Oct 06 '22 09:10

JESii


In pipeline jobs you can wrap your step(s) with timeout as follows:

timeout(time: 5, unit: 'MINUTES') {
   // steps to execute
}
like image 24
katrash Avatar answered Oct 06 '22 11:10

katrash