简体   繁体   English

如何使用github存储库在jenkins中触发单个作业

[英]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是否在版本AB之间发生了变化,

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.

相关问题 如何使用 github 操作从 Github 中的存储库 A 的工作流作业触发存储库 B(下游作业)中的工作流作业 - How to trigger a workflow job in repository B(downstream job) from workflow job of repository A in Github using github actions 如何在Jenkins Job中克隆github组织的私有存储库 - How to Clone a private repository of github organization in a Jenkins Job Github + Jenkins >>如何触发代码库中“Commit and Push”的构建? - Github + Jenkins >> How to trigger build on “Commit and Push” in code repository? 每当在github org上创建存储库时,如何触发jenkins? - How to trigger jenkins every time a repository is created on github org? 如何在对私有github存储库进行推送时触发Jenkins构建 - How to trigger a Jenkins build when a push is made to a private github repository 触发GitHub PUSH上的Jenkins作业到特定分支 - Trigger Jenkins job on GitHub PUSH to specific branch 在Github上触发特定的Jenkins作业推送到特定目录 - Trigger Specific Jenkins Job on Github Push to specific Directory 如何在多个系统上设置Jenkins Github作业 - How to setup Jenkins Github job on multiple system 如何合并2 github存储库以触发pullrequest? - How merge 2 github repository to trigger a pullrequest? 如何从多个存储库触发詹金斯管道 - How to trigger a jenkins pipeline from multiple repository
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM