21

This is a question related to How to make SCM polling work with the Jenkins Workflow plugin. That thread answers how to use SCM polling in a pipeline script once SCM polling is enabled but does not cover how to enable SCM polling.

For example, if you wanted to use the mulit-branch pipeline plugin to create jobs automatically using a Jenkinsfile there is not a way I know of to have the "Poll SCM" option enabled in the job. This makes it difficult to provision on-demand environments such as creating a docker container that has the jobs setup from the beginning. Because you would have to sign-in to Jenkins and go to the configuration and select the "Poll SCM" option once the container was started. Cloudbees offers a template plugin to help solve this problem.

However this is not available to Jenkins using the free version. Is there any workaround or solution for users on the free version of Jenkins?

4

4 回答 4

25

如果您想使用多分支管道插件使用 Jenkinsfile 自动创建作业,我不知道有一种方法可以在作业中启用“轮询 SCM”选项

也不需要任何东西。多分支项目对整个分支索引有一个可配置的轮询间隔,它也用作每个分支的构建触发器,并且还将自动接收 webhook。

于 2016-03-21T21:32:08.820 回答
23

要回答如何启用 SCM 轮询的问题,您需要执行以下操作。

使用管道语法生成器和“属性:设置作业属性”,您可以生成以下将启用 SCM 轮询的内容。

properties([pipelineTriggers([pollSCM('H * * * *')])])

然而,正如 Jesse Glick 指出的多分支管道,您不需要启用 SCM 轮询。

于 2017-05-03T23:28:54.883 回答
3

为了让我的 Bitbucket 连接到网络挂钩,我必须将以下内容添加到我的声明性管道中:

pipeline {
    stages {
        stage('Initialize') {
            steps {
                //enable remote triggers
                script {
                    properties([pipelineTriggers([pollSCM('')])])
                }
                //define scm connection for polling
                git branch: BRANCH_NAME, credentialsId: 'my-credentials', url: 'ssh://git@stash.server.fqdn/stash/my-project.git'
            }
        }
    }
}

这允许重建分支,而无需扫描整个multibranchiverse。这在使用 Bitbucket Project /Github Team-multibranch 项目时特别有价值。一旦您有几个存储库/分支,扫描可能需要几分钟。

通过直接挂钩到分支,您可以更快地获得构建结果,并且没有任何副作用。

注意:在声明性管道中,属性调用必须由脚本块包装。

于 2019-01-14T13:22:36.863 回答
3

我正在考虑同样的问题。

如果您使用的是Github或之类的在线 Git 服务Bitbucket,我认为您可以使用它们的Webhooks功能来解决它​​。我还不能测试解决方案,但它应该可以工作。

在您的Multibranch Pipeline配置中,启用该Trigger builds remotely选项。

然后,您需要使用路径(如 Jenkins 配置说明中所述)在您的存储库上启用 Github/Bitbucket Webhook:JENKINS_URL/job/test/build?token=TOKEN_NAME

于 2016-03-20T19:42:29.653 回答