简体   繁体   English

如何从多个存储库触发詹金斯管道

[英]How to trigger a jenkins pipeline from multiple repository

I am relatively new to jenkins and I am working on a big project that pulls from multiple repo to build. 我对jenkins来说还比较陌生,并且我正在从事一个大型项目,该项目从多个存储库中构建。 I wrote a declarative pipeline with shell commands that I use that pulls from the required repos and build the project and everything are working but I want to connect this pipeline to all these repos so every time that there is a new commit or merge request, that triggers jenkins and starts this pipeline and then based on the build result I tag the git. 我用外壳程序命令编写了一个声明性管道,该命令从所需的存储库中提取并构建项目,并且一切正常,但是我想将此管道连接到所有这些存储库,以便每次有新的提交或合并请求时,触发jenkins并启动此管道,然后根据构建结果标记git。 I know how to do this for one repo but I don't know how to do it for multiple repo. 我知道如何为一个仓库执行此操作,但我不知道如何为多个仓库进行操作。

If you have multiple repositories which should trigger Jenkins builds, the respective repositories need to have Jenkinsfiles in place. 如果您有多个应该触发Jenkins构建的存储库,则各个存储库都需要有Jenkinsfiles。

The key is that every repository should call a JenkinsSharedLibrary, which gives you the possibility to maintain your jenkins builds in one central source, instead of having multiple "hardcoded" jenkinsfiles per repository. 关键是每个存储库都应调用JenkinsSharedLibrary,这使您可以在一个中央源中维护jenkins构建,而不是每个存储库具有多个“硬编码” jenkins文件。

This article describes the use case of a shared library and how to use Jenkins across multiple git repos. 本文介绍了共享库的用例以及如何在多个git仓库中使用Jenkins。

https://bjurr.com/managing-1000-repos-in-jenkins-with-a-breeze/ https://bjurr.com/managing-1000-repos-in-jenkins-with-a-breeze/

Because of our network infrastructure I couldn't use webhook to trigger jenkins but the solution that I am using now is I created a runner for each repo and I wrote a curl command to trigger jenkins with so each time that there is a new commit to each of those repos the runner starts a new job, executes that curl command and triggers my jenkins job. 由于我们的网络基础架构,我无法使用webhook来触发jenkins,但现在使用的解决方案是我为每个回购创建了一个运行器,并编写了curl命令来触发jenkins,因此每次有新提交时跑步者在每个仓库中都开始一项新工作,执行curl命令并触发我的詹金斯工作。

This is the curl command that I am using in case someone needed it: 这是我在有人需要时使用的curl命令:

curl -i -X POST --user [JENKINS_USERNAME]:[JENKINS_PASSWORD] 'http://[JENKINS_IP]:[JENKINS_PORT]/job/[JENKINS_JOB_NAME]/build?token=[TOKEN_GENERATED_INSIDE_JENKINS]&cause=[ADDITIONAL_INFORMATION_THAT_YOU_WANT_TO_PRINT]'

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

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