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

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

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-2.html
匿名

发表评论

匿名网友

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

确定