从 Jenkins 中的多个存储库进行轮询

Polling from multiple repositories in Jenkins

我在堆栈中找不到我的问题的答案,如果重复,抱歉。

假设我在 Github 上有回购 A,我的 Jenkinsfile 所在的位置,在 [=38 上有回购 B =],我所有的源代码都在这里。

对于我的工作,我已经从 repo 'A' 中设置了 'Pipeline script from SCM',添加了 'Polling ignores commit in certain paths' 包含的区域只包含这个 Jenkinsfile。

在 Jenkinsfile 中,我使用 checkout 插件来拉回购 'B' 添加了 PathRestriction 扩展。 我还添加了 pollSCM 到 'triggers',值为 'H/5 * * * *'.

但是每当我提交一些东西到 repo 'A' 而没有对这个 Jenkinsfile 进行任何更改时,无论如何都会触发构建。

我的问题是:当 repo 'A' 中的 Jenkinsfile 或我的源代码发生更改时,如何将我的构建设置为仅触发?

有两种方法可以仅在特定文件更改时触发构建。

1. 脚本挂钩:在 git 服务器端,创建一个挂钩,检查最后一次提交是否更改了 Jenkinsfile,如果为真,发送一个 post 到配置有 'Trigger build remotely'.

2. 提交:仅使用 Jenkinsfile 创建一个 repo,因此对这个 repo 的每次提交都将是对 Jenkinsfile 的更改。

我强烈建议您改变方法并使用 Jenkins shared library,这是跨多个项目/工作共享和管理管道的更好方法