简体   繁体   English

如何在我的 jenkinsfile 中配置“扫描多分支管道触发器”?

[英]How do I configure "Scan Multibranch Pipeline Triggers" in my jenkinsfile?

Right now I manually configure my all my multibranch pipeline jobs and set "Scan Multibranch Pipeline Triggers" to 3 minutes.现在我手动配置我所有的多分支管道作业并将“扫描多分支管道触发器”设置为 3 分钟。

How do I put this in my Jenkinsfile ?我如何把它放在我的Jenkinsfile I can't find examples of this.我找不到这方面的例子。 Is "Scan Multibranch Pipeline Triggers" available in the triggers{} block?触发器块中是否提供“扫描多分支管道触发器”? triggers{}

The settings on the multibranch configuration page only configure the multibranch scan job itself, not the individual jobs created inside the multibranch "folder".多分支配置页面上的设置仅配置多分支扫描作业本身,而不是在多分支“文件夹”内创建的单个作业。

The option under "Scan Multibranch Pipeline Triggers" that says "Periodically if not otherwise run" is only a trigger for when the multibranch job will scan for new branches. “Scan Multibranch Pipeline Triggers”下的“Periodically if not running”选项只是多分支作业扫描新分支时的触发器。 If changes are found to existing branches, or if new branches are discovered with a Jenkinsfile that match your branch specifications, a new build will be triggered, but this is not intended to be the way a job is triggered.如果发现现有分支发生更改,或者发现新分支与 Jenkinsfile 匹配您的分支规范,则将触发新构建,但这不是触发作业的方式。

Actually, you can disable the automatic build when changes are found by adding a property to the SCM configuration to "Disable automatic SCM Triggering".实际上,您可以通过将属性添加到 SCM 配置以“禁用自动 SCM 触发”来在发现更改时禁用自动构建。 Then then you will see the multibranch scan trigger, but the jobs themselves won't build, even if there are changes found.然后您将看到多分支扫描触发器,但即使发现更改,作业本身也不会构建。

To trigger jobs, ideally you should use a webhook if you can.要触发作业,理想情况下您应该尽可能使用 webhook。 If you use a git hook using the git plugin (not the github plugin), then you need to enable the PollSCM trigger (though you can set it to only poll rarely, or not at all).如果您通过 git 插件(而不是 github 插件)使用 git hook,那么您需要启用 PollSCM 触发器(尽管您可以将其设置为仅轮询很少或根本不轮询)。

If you just want normal triggering options, as of 2.22, you can configure the either cron or pollSCM triggers.如果您只想要普通的触发选项,从 2.22 开始,您可以配置cronpollSCM触发器。

pipeline {
    triggers {
        cron('H/4 * * * 1-5')
        pollSCM('0 0 * * 0')
    }

Then I believe you can configure webhooks to inform your multibranch job when to do a scan.然后我相信您可以配置 webhooks 来通知您的多分支作业何时进行扫描。 I haven't tried that.我没试过。 I just tell it to scan every hour or a couple times per day using the "Periodically if not otherwise run".我只是告诉它使用“如果不以其他方式运行,则定期运行”每小时或每天扫描几次。

Note, the same thing applies for the build discarder and other things you configure in your multibranch job.请注意,同样的事情适用于构建丢弃器和您在多分支作业中配置的其他内容。 In the web UI, you can only configure the multibranch job itself, not the individual jobs created from it.在 Web UI 中,您只能配置多分支作业本身,而不能配置从它创建的单个作业。 You have to use Pipeline to configure the jobs.您必须使用 Pipeline 来配置作业。

If your're using the JobDSL Jenkins plugin for creating jobs, then you can add following lines to configure "Scan Multibranch Pipeline Triggers":如果您使用JobDSL Jenkins 插件来创建作业,那么您可以添加以下行来配置“扫描多分支管道触发器”:

configure {
    it / 'triggers' << 'com.cloudbees.hudson.plugins.folder.computed.PeriodicFolderTrigger'{
        spec '* * * * *'
        interval "60000"
    }
}

Using the JobDSL Jenkins Plugin for multibranch pipeline job, the periodic folder trigger can be configured as given below.使用 JobDSL Jenkins 插件进行多分支管道作业,可以如下配置定期文件夹触发器。 In this example, the maximum amount of time since the last indexing that is allowed to elapse before an indexing is triggered will be seven days.在此示例中,在触发索引之前允许经过的上次索引以来的最长时间为 7 天。

multibranchPipelineJob('my-awesome-job') {
    triggers {
        periodicFolderTrigger {
            interval("7d")
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM