Timeout on a Build Step of Jenkins

2020-06-07 06:39发布

问题:

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.

回答1:

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:



回答2:

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

timeout(time: 5, unit: 'MINUTES') { // steps to execute }



回答3:

There is no such functionality that I am aware of. JENKINS-8900 requests it.



回答4:

This question was originally asked before the Jenkins Pipeline existed. Although you can continue to use and configure Jenkins through the GUI, it's currently recommended to transition your projects to the pipeline. Using the Pipeline allows you to track changes to your pipeline, and store it as code so it's easy to recreate your build on any machine if you need to move your Jenkins server.

Using the pipeline, adding a timeout to a very specific part of your build is trivial. The pipeline syntax is simple and easy to use.

timeout(time:5, unit:'DAYS') {
    input message:'Approve deployment?', submitter: 'it-ops'
}

Related question: How to add a timeout step to Jenkins Pipeline

Example shamelessly taken from: CloudBees Top 10 Best Practices for Jenkins Pipeline Plugin



回答5:

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



回答6:

I think the timeout command from GNU coreutils might be what you want. This is under the assumption that your build steps are scripts.



回答7:

Build-timeout Plugin isn't applicable to pipelines. refer to wiki

For pipeline time out, try something like:

timeout(time: 30, unit: 'MINUTES') {
  node {
    sh 'foo'
  }
}

Similar answer from another thread: How to add a timeout step to Jenkins Pipeline



回答8:

The easiest way (and that is the way I am doing that) is to actually have different project dependent on each other and to build them in a row. It's not perfect, but the other option would be to monitor execution of different plugins with different tools/build behaviour.

Still, the approach will work, although it does suck...

BTW, there is a nice plugin which can help you out using a set of project - Build Pipeline plugin. I am using it right now to both visualize and verify the pipeline I have created. It is really handy...



回答9:

If you don't want to use the Jenkins plugin and want to timeout a script or any command then you can use the Linux inbuilt utility "timeout".

timeout -s KILL 1m ./test

The above command will run test executable for 1 minute and if it continues to execute after the timeout then the command will timeout and kill the process by KILL utility.



回答10:

Please install Build Timeout plugin for your Jenkins.

Jenkins> Manage Jenkins> Manage Plugins

search for Build Timeout in available tab.. Install it. You would be finding it in Build environment as "Abort the build if it's stuck". Set the Timeout strategy and time. Absolute Deadline Elastic Likely Stuck No Activity

in my case i have used No Activity.

Hope it Helps.