Timeout on a Build Step of Jenkins

2020-06-07 06:27发布

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.

10条回答
霸刀☆藐视天下
2楼-- · 2020-06-07 06:55

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

查看更多
不美不萌又怎样
3楼-- · 2020-06-07 06:58

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

查看更多
贼婆χ
4楼-- · 2020-06-07 06:58

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

查看更多
女痞
5楼-- · 2020-06-07 07:04

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...

查看更多
登录 后发表回答