Jenkins 和 GitLab:如何设置不是由挂钩触发的 SCM 感知作业?

Jenkins and GitLab: How to setup SCM aware job which is not triggered by the hook?

为了提供一些背景信息,问题是关于 GitLab 和 Jenkins 设置的。

我知道如何设置网络钩子,我知道如何设置由钩子触发的作业。问题是我需要有多个作业并且只有一个入口点(父作业)触发器。

下游作业同时需要 git 回购感知,所以我必须为它们设置回购 url。这导致它们被挂钩独立触发,我不希望这样,因为这意味着它们被触发了两次。

另一方面,如果我没有在下游作业上配置 repo url 并且父作业触发了它,它会失败,因为它无法进行结帐。

我可能会尝试修改一些 'execute shell' 构建步骤,我认为这不是一个有效的方法。有没有人有解决这个问题的好建议?

此处供参考的是GitLab Jenkins plugin documentation,据此:

Plugin will parse the GitLab payload and extract the branch for which the commit is being pushed and changes made. It will then scan all Git projects in Jenkins and start the build for those that:

  • match url of the GitLab repo
  • match the configured refspec pattern if any
  • and match committed GitLab branch

我尝试使用不同的设置,但效果不佳。

对于您只想获得本地触发器的项目,只需在其他行为中启用不触发基于提交的通知 ] git 插件。 (https://github.com/elvanja/jenkins-gitlab-hook-plugin/issues/11#issuecomment-35385032,正如您实际发现的那样)。

但更好的解决方案可能是让您的下游作业引用主作业在本地克隆的存储库(不确定是否真的可能),因此插件永远不会考虑它们来安排构建,因为 git url不匹配。