在 Jenkins 多分支管道上触发重复构建 [英] Duplicate builds triggered on Jenkins multibranch pipeline

查看:18
本文介绍了在 Jenkins 多分支管道上触发重复构建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们看到 Jenkins 多分支管道项目触发了重复构建.构建通常使用来自 Bitbucket 的使用此插件的推送通知触发:https://marketplace.atlassian.com/plugins/com.nerdwin15.stash-stash-webhook-jenkins/server/overview

We are seeing duplicate builds triggered on Jenkins multibranch pipeline projects. Builds are normally triggered using push notifications from Bitbucket using this plugin: https://marketplace.atlassian.com/plugins/com.nerdwin15.stash-stash-webhook-jenkins/server/overview

但是,出于某种原因,我们现在看到了双重"构建.如果您查看触发的 2 个构建,一个由提交通知"触发,另一个由分支索引"触发.

However, we are now seeing 'double' builds for some reason. If you look at the 2 builds that are triggered, one is triggered by a 'commit notification', and the other is triggered by 'Branch Indexing'.

是什么导致了分支索引,为什么它会触发构建?我们没有添加或删除分支,这只是一个正常的提交/推送.

为了让它更复杂,它并不是一直都在发生.有一次我认为它只发生在合并之后,但事实并非如此.此外,阻止它的一种方法似乎是删除作业的构建历史记录(这显然不理想).

To make it more complicated, it's not happening all the time. At one point I thought it was only happening after merges, but that's not the case. Also, one way to stop it seems to be by deleting the build history for a job (which obviously isn't ideal).

我们正在通过管道脚本设置作业的属性,但只是为了丢弃旧版本:

We are setting properties on the job from the pipeline script, but only to discard old builds:

properties([buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '', numToKeepStr: '20'))])

另一个混淆的来源似乎是是否应该启用轮询(没有间隔)以便推送通知适用于 Git 插件.Git 插件的文档表明这是必需的,并且确实似乎适用于正常"管道构建,但似乎不需要多分支管道构建.这是正确的吗?来自 Jenkins Git 插件 wiki:

Another source of confusion seems to be if one should have polling enabled (with no interval) in order for push notifications to work for the Git plugin. The documentation for the Git plugin indicates this is required, and indeed seems to be for 'normal' pipeline builds, but doesn't seem to be required for multibranch pipeline builds. Is this correct? From the Jenkins Git Plugin wiki:

这将扫描所有符合以下条件的作业:

This will scan all the jobs that:

已启用构建触发器 > 轮询 SCM.没有轮询时间表必需的.配置为在指定的 URL 构建存储库配置为构建可选指定的分支或提交 ID对于满足这些条件的职位,将立即进行轮询触发.如果轮询发现值得构建的更改,则构建将依次被触发.

Have Build Triggers > Poll SCM enabled. No polling Schedule is required. Are configured to build the repository at the specified URL Are configured to build the optionally specified branches or commit ID For jobs that meet these conditions, polling will be immediately triggered. If polling finds a change worthy of a build, a build will in turn be triggered.

我们正在使用 Bitbucket 4.8.4 和 Jenkins 2.30(以及所有最新的管道插件).

We are using Bitbucket 4.8.4 and Jenkins 2.30 (and all the latest pipeline plugins).

推荐答案

正如其他答案已经建议的那样,不允许并发构建"选项就是您想要的.你可以通过 Jenkinsfile 得到它:

As the other answer already suggested the "Do not allow concurrent builds" option is what you want. And you can get that via the Jenkinsfile:

 properties ([
      buildDiscarder(logRotator(artifactNumToKeepStr: '5', daysToKeepStr: '15')),
      disableConcurrentBuilds()
    ])

这不是这里实际问题的解决方案.但它对某些人似乎仍然有帮助,所以只要我们没有更好的答案,我就会留下它.

This is not the solution for the actual problem here. but it still seems helpful to some people, so I'll leave it as long as we don't have a better answer.

这篇关于在 Jenkins 多分支管道上触发重复构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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