如何向 Jenkins Pipeline 添加超时步骤 [英] How to add a timeout step to Jenkins Pipeline

查看:87
本文介绍了如何向 Jenkins Pipeline 添加超时步骤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您使用自由风格的项目时,您可以设置在 20 分钟后构建如果未结束则中止.Jenkins 多分支管道项目怎么可能做到这一点?

When you are using a free style project you can set that after 20 minutes the build is aborted if not concluded. How is this possible with a Jenkins Multi Branch Pipeline Project?

推荐答案

您可以使用 超时 步骤:

timeout(20) {
  node {
    sh 'foo'
  }
}

如果您需要不同的TimeUnitMINUTES,你可以提供 unit 参数:

If you need a different TimeUnit than MINUTES, you can supply the unit argument:

timeout(time: 20, unit: 'SECONDS') {

编辑 2018 年 8 月: 现在使用更常见的 声明式管道(很容易被顶级pipeline 结构识别),也可以使用options 在不同级别(每个整体管道或每个阶段):

EDIT Aug 2018: Nowadays with the more common declarative pipelines (easily recognized by the top-level pipeline construct), timeouts can also be specified using options on different levels (per overall pipeline or per stage):

pipeline {
  options {
      timeout(time: 1, unit: 'HOURS') 
  }
  stages { .. }
  // ..
}

不过,如果您想对声明式管道中的单个步骤应用超时,则可以按上述方式使用.

Still, if you want to apply a timeout to a single step in a declarative pipeline, it can be used as described above.

这篇关于如何向 Jenkins Pipeline 添加超时步骤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆