【问题标题】:Jenkins - trigger a project only if it's not already runningJenkins - 仅在项目尚未运行时触发项目
【发布时间】:2013-07-19 03:12:20
【问题描述】:

这是我的情况:

  1. 在大约 1 小时内在构建上运行的迷你测试套件
  2. 在大约 12 小时内在构建上运行的完整测试套件

我想连续触发(1),如果(1)PASSES,那么我想触发(2)。

但是,当构建稳定且 (1) 频繁通过时,我不想排队 (2) 的大量作业。如何在 Jenkins 中进行设置?我能想到的两种可能的解决方案是

  • 以某种方式永远不允许 Jenkins 在 (2) 上保留作业队列,或者
  • 仅在 (2) 尚未运行时触发

但我也不知道该怎么做,有什么想法吗?

【问题讨论】:

  • “Advance Project Options -> Quiet period”功能会做你想要的吗?
  • 试试 BuildResultTrigger - 虽然我不能 100% 确定它是否会按照您希望的方式工作...
  • Build Blocker Plugin 可以很方便地实现这一点,它还允许配置非常细粒度的阻塞行为。

标签: build jenkins


【解决方案1】:
A possible solution for : only trigger (2) if it's not already running

All jenkins jobs have their data exposed in XML and json format via this URL:
*http://jenkins_hostname/job/job_name/build_number/api/xml*

This XML has a section of <building> in which you will know if the job is building or not:
<building> false </building>


If you can somehow read this from scripts?/code? then you will always know if job is running.

Otherwise, there is a boolean groovy API which reads this data and returns true or false (can be used easily in pipelines):

*def JobName = 'JOB_NAME'
def nextJob = Hudson.instance.getItem(JobName)
def running = nextJob.lastBuild.building
if (running) {
   println "${nextJobName} is already running. Not launching"
} else {
   println "${nextJobName} is not running. Launching..."
}*

【讨论】:

    猜你喜欢
    • 2022-07-03
    • 1970-01-01
    • 2019-08-19
    • 2014-10-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-03
    相关资源
    最近更新 更多