如果具有相同参数的 Jenkins 构建正在进行中,则阻止执行。

huangapple go评论92阅读模式
英文:

Block Jenkins Builds execution if one with same parameters is already in progress

问题

我知道有一个名为throttle concurrent builds plugin的插件,它可以防止具有相同参数的两个构建同时运行,但即使使用了该设置,Jenkins仍然会将第二个相同的构建排队,最终会执行它。

我找不到一种方法或插件,可以在已经运行另一个相同构建时阻止/丢弃/不排队第二个作业。有一个插件,但似乎已被弃用。

在这个问题中找到了另一个相关的问题,但我没有看到该插件适用于流水线,只适用于自由风格项目。

有什么建议吗?

英文:

I know there is the throttle concurrent builds plugin that prevents two builds with the same parameters to run concurrently but even with that setup Jenkins still queues the second identical build that will eventually be executed.

I can't find a way or a plugin that allows me to block/discard/NotQueue the second job when another identical one is already running. There is this one but seems like its being deprecated.

Stumbled across this other question which might apply but I don't see the plugin available for Pipelines, just freestyle projects.

Any suggestions?

答案1

得分: 1

构建是如何触发的?如果有一个提交触发了构建,你可以通过在流水线的末尾将该提交标记为“已构建”,以确保不会为相同的提交触发构建。在流水线的开始处,检查构建是否已经完成,如果是,则中止构建。

如果以其他方式触发构建,你唯一的选择是记录已经使用了哪些参数进行了构建,可以将这些记录保存在文件或数据库中。然后,在运行构建之前读取这些数据源。

编辑:你可以在父作业中使用类似这样的函数来获取前几个作业的构建参数。然后,检查这些参数是否包含即将触发的构建中的相同参数。如果是,则不触发构建。

英文:

How are the builds being triggered? If there is a commit that is triggering them, you can ensure that the build doesn't get triggered for the same commit by marking the commit as "built" at the end of the pipeline. At the start of the pipeline, check to see if the build has been already built and if so, abort the build.

If it gets triggered in some other way, your only option is to record which builds have gone through with which parameters, in something like a file or a database. Then, read this data source before the build is run.

Edit: You could use a function such as this in the parent job to get the build parameters of the previous couple of jobs. Then, check if those params contain the same params in the build you are going to trigger. If so, don't trigger the build.

huangapple
  • 本文由 发表于 2023年8月9日 17:05:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/76866176.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定