如何使用 github 存储库在 jenkins 中触发单个作业
我们的项目托管在github上,我们已经设置了一个Jenkins服务器,问题是我们的项目中有很多模块,每个模块都有自己的工作,之前我们使用perforce,它可以更新指定模块中的源代码,因此只能更新属于已修改模块的作业将被触发,但 git 会将整个项目视为单个存储库,并且它不会告诉我们哪些模块已被修改,因此 Jenkinks 无法执行相同的操作。
我调查了 git submodule 和 git subtree,似乎它们都有点复杂,有没有更简单的方法来存档?
Our project is hosted on github and we've setup a Jenkins server, the question is we have lots of modules in the project and every module has it's own job, previously we were using perforce that it can update source code in specified modules thus only the jobs belong to those modules which have been modified will be triggered, but git will treat the whole project as a single repository and it won't tell us which modules have been modified therefore Jenkinks can't do the same thing.
I've investigated on git submodule and git subtree, seems all of them are a little complicated, is there a easier way to archive this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Git 会通过
git log
告诉您此信息(请参阅--exit-code
参数,该参数由--quiet
隐含)。我不知道 Jenkins Git 插件是否会给你这种技巧,但你可以用一个简单的 shell 脚本轻松地做到这一点。要检查目录
dir
在版本A
和B
之间是否发生更改,Git will tell you this information with
git log
(see the--exit-code
parameter, which is implied by--quiet
). I don't know if the Jenkins Git plugin will will give you this kind of finesse, but you can do it with a simple shell script easily enough.To check if the directory
dir
changed between revisionA
andB
,我创建了一个 Jenkins 插件来实现这个目标,它在这里 https://github.com/jameswangz/ github-共享存储库。
I have created a Jenkins Plugin to achieve this goal, it's here https://github.com/jameswangz/github-shared-repository.
现在,您可以使用 Jenkins 的常规 Git 插件:您可以设置它应该监视并开始执行作业的目录,以及忽略哪些目录。
如果您对存储库中的每个项目/模块都有一个构建作业,并且您希望仅在相关目录发生更改时才调用构建(例如,模块的目录以及任何公共/共享模块目录),则此方法效果最佳)。
为了说明这一点,我们没有共享模块的构建作业,但自然地,每个模块都有作业。因此,我们将插件设置为仅监视模块的目录和 commons 目录:这样,项目将在对该目录的每次相关提交以及对 commons 目录的提交时重建。
Nowadays you can make use of the regular Git plugin of Jenkins: you can set which directories it should watch and commence the execution of the job, and which to ignore.
This works best if you have a build job for each project/module in the repository, and you want to invoke the build only when relevant directories have been changed (for example, the very directory of the module, and any commons/shared module directories).
To drive the point home, we don’t have build jobs for the shared module, but we do have, naturally, jobs for every module. So we set the plugin to watch only the module’s directory and the commons directory: this way the project will be rebuilt on every relevant commit to the directory, as well as commits to the commons directory.