简体   繁体   English

如何通过推送到其他存储库来触发GitHub存储库的Jenkins构建?

[英]How can I make a Jenkins build for a GitHub repository be triggered by a push to a different repository?

I have a GitHub repository (call it X) for a Python code package, and a separate GitHub repository (call it X-tests) that contains the tests for that package (they're separate repositories because the one containing the tests is private so that it can run other private code). 我有一个Python代码包的GitHub存储库(称为X),还有一个单独的GitHub存储库(称为X-tests),其中包含该程序包的测试(它们是独立的存储库,因为包含测试的容器是私有的,因此它可以运行其他私人代码)。 I would like to make it so that when someone pushes to the X repository, Jenkins will run the tests from the X-tests repository, and then do some other stuff related to the X repository (eg making a pip wheel). 我想这样做,以便当有人推送到X存储库时,Jenkins将从X-tests存储库运行测试,然后执行与X存储库相关的其他操作(例如,制作一个pip wheel)。

The only way I can think of to do this is to have three separate Jenkins jobs: 我能想到的唯一方法是拥有三个单独的詹金斯工作:

  1. a job that does nothing, whose GitHub repository is X, where builds are triggered by pushes to X 一项无所事事的工作,其GitHub存储库为X,通过推送到X触发构建
  2. a job that runs the tests, whose GitHub repository is X-test, where builds are triggered by completion of job 1 一个运行测试的工作,其GitHub存储库为X-test,其中,构建是通过完成工作1触发的
  3. a job that makes the pip wheel etc., whose GitHub repository is X, where builds are triggered by completion of job 2 GitHub储存库为X的制作点子等的工作,其中工作2的完成触发构建

Is there any simpler way to do it? 有没有更简单的方法可以做到这一点?

I think this is a pretty standard approach to implementing a simple build-test-posttest pipeline. 我认为这是实现简单的构建-测试-测试后管道的非常标准的方法。 Job 1 is name -commit-stage, job 2 is name -test-stage or name-integration-stage and a third job for your pip-wheel. 作业1是name -commit-stage,作业2是name -test-stage或name-integration-stage,第三项是您的摆轮。

You can see a more complex pipeline in the build pipeline jenkins plugin. 您可以在构建管道jenkins插件中看到更复杂的管道。

Check if your third job should be using job 1's artifacts instead of repository X. This will bring atomicity to your pipeline as someone could push something to your repository X while a job has already started. 检查您的第三个作业是否应该使用作业1的工件而不是存储库X。这将给您的管道带来原子性,因为有人可以在作业开始时将某些东西推入存储库X。 The Copy Artifact Plugin is useful for that, or you can just reference the local job 1 workspace as a source of your job 3 (as a parameter in a build step). 复制工件插件”对此很有用,或者您可以仅引用本地作业1工作区作为作业3的源(作为构建步骤中的参数)。

You also need to make sure that changes to repository X-Tests should be pushed before changes to repository X, as job 2 may use code in repository X-Tests that is not in sync with repository X, leading to test failures. 您还需要确保在更改存储库X之前先推送对存储库X测试的更改,因为作业2可能会使用存储库X测试中与存储库X不同步的代码,从而导致测试失败。

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

相关问题 如何在不登录的情况下从 Github 存储库下载文件? - How can I download files from a Github repository without logging in? 如何在 django3.0.2 python3.6 中创建一个带有常量的文件并在所有应用程序中访问它。 任何 github 存储库也很有用 - How can i make a file with constants in django3.0.2 python3.6 and access it in all applications . Any github repository is also useful 无法安装github存储库 - Can't install a github repository 如何使用 PyGithub 检查给定文件是否存在于 Github 存储库中? - How can I check if a given file is present in a Github repository using PyGithub? 你如何创建一个 GitHub Repository 以便我可以自动导入和导出 python 脚本? - How do you create a GitHub Repository so that I can automatically import and export python scripts? 从GitHub存储库构建Docker映像 - Build Docker image from GitHub repository 你怎么知道github存储库是用于python 2还是python 3 - how can you tell if github repository is for python 2 or python 3 如何从 github 存储库中获取分支列表? - How do i get a list of branches from a github repository? 如何使用 GitPython 拉取远程存储库? - How can I pull a remote repository with GitPython? 如何将存储库添加到 conda - How can I add a repository to conda
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM