[英]How to trigger a individual job in jenkins with github repository
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. 我们的项目是在github上托管的,我们已经设置了一个Jenkins服务器,问题是我们在项目中有很多模块,每个模块都有自己的工作,以前我们使用perforce它可以更新指定模块中的源代码属于那些已被修改的模块的作业将被触发,但是git会将整个项目视为单个存储库,它不会告诉我们哪些模块已被修改,因此Jenkinks不能做同样的事情。
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? 我已经调查了git子模块和git子树,看起来所有这些都有点复杂,有没有更简单的方法来存档?
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. 如今,您可以使用Jenkins的常规Git插件:您可以设置应监视的目录并开始执行作业,而忽略哪些目录。 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.
所以我们设置插件只监视模块的目录和commons目录:这样项目将在目录的每个相关提交上重建,以及提交到commons目录。
Git will tell you this information with git log
(see the --exit-code
parameter, which is implied by --quiet
). Git将通过
git log
告诉您此信息(请参阅--exit-code
参数,该参数由--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. 我不知道Jenkins Git插件是否会为您提供这种技巧,但是您可以使用简单的shell脚本轻松地做到这一点。
To check if the directory dir
changed between revision A
and B
, 要检查目录
dir
是否在版本A
和B
之间发生了变化,
if git log --quiet A..B -- dir ; then
# there are no changes in "dir" between rev A and B
else
# there are changes
fi
我创建了一个Jenkins插件来实现此目标,它位于https://github.com/jameswangz/github-shared-repository 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.