一个种子作业可以处理来自多个存储库的DSL吗? [英] Can a single seed job process DSLs from multiple repos?

查看:90
本文介绍了一个种子作业可以处理来自多个存储库的DSL吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近设法将几个手动创建的作业转换为DSL脚本(内联到临时的种子"作业中),并且感到如此的简单是令人惊喜的.现在,我想摆脱 multiple 种子作业,并尝试更整洁地构建事物.

I recently managed to convert several manually-created jobs to DSL scripts (inlined into temporary 'seed' jobs), and was pleasantly surprised how straightforward it was. Now I'd like to get rid of the multiple seed jobs and try to structure things more cleanly.

为此,我创建了一个新的jenkins-ci存储库,并将所有Groovy DSL脚本提交给它.然后,我创建了一个job-generator Jenkins作业,该作业从jenkins-ci存储库中提取,并且只有一个 Process Job DSLs 步骤.此步骤已选中在文件系统上查找框,并且 DSL脚本字段设置为jobs/*.groovy.在已经有了全局推送通知的情况下,此操作大致按预期进行:如果我对jenkins-ci存储库进行了更改,则job-generator作业将自动运行并重新生成所有作业-太棒了!

To that end, I created a new jenkins-ci repo and committed all the Groovy DSL scripts to it. Then I created a job-generator Jenkins job that pulls from the jenkins-ci repo and has a single Process Job DSLs step. This step has the Look on Filesystem box ticked, with the DSL Scripts field set to jobs/*.groovy. With global push notifications already in place, this works more-or-less as intended: if I make a change to the jenkins-ci repo, the job-generator job automatically runs and regenerates all the jobs—awesome!

我对该解决方案不满意的是,它的参考位置差:该作业的DSL脚本位于与代码完全独立的存储库中.我真正想要的是将作业DSL脚本保存在每个单独的代码存储库中的jenkins子文件夹中,并有一个单个种子作业来处理它们.这样,就可以在代码旁边同时查看对CI设置的更改.对我来说,这就像一个理想设置.

What I don't like about this solution is that it has poor locality of reference: the DSL scripts for the job live in a completely separate repository from the code. What I'd really like is to keep the job DSL scripts in each individual code repository, in a jenkins subfolder, and have a single seed job that processes them all. That way, changes to CI setup could be code-reviewed right alongside the code. To me, that just feels like an ideal setup.

不幸的是,我对如何实现这一目标尚无明确的想法.如果我能找到一种方法来使种子作业监视多个存储库,以便对其中任何一个的提交都会触发它,也许我可以在 Process Job DSLs 步骤之前注入另一个构建步骤,然后(以某种方式)编写了通往胜利的脚本,但是...我不确定如何获得. (我当然不想只生成DSL脚本就对生成器作业中的每个仓库进行完整克隆!)

Unfortunately, I don't have a clear idea about how to make this happen. If I could figure out a way to make the seed job watch multiple repos, such that a commit to any one of them would trigger it, perhaps I could inject another build step before the Process Job DSLs step and (somehow) script my way to victory, but... I'm unsure how to even get to that point. (I certainly don't want to do full clones of each repo in the generator job just to pull in the DSL scripts!)

我怀疑我不是第一个希望他们可以将Job DSL脚本与代码放在一起的人,尽管也许我高估了收益.感谢您提供有关此主题的任何建议!

I suspect I'm not the first person to wish they could put the Job DSL scripts alongside the code, though perhaps I'm over-estimating the benefits. Any advice on this topic would be much appreciated—thanks!

推荐答案

不幸的是,没有直接的方法可以解决这个问题.几个功能请求已打开( JENKINS-33275

Unfortunately there is no direct way of solving this. Several feature requests have been opened (JENKINS-33275, JENKINS-37220), but AFAIK no one is working on any of them.

作为解决方法,您可以使用管道多分支插件并为您的每个存储库创建一个多分支项目.然后,您必须向每个存储库/分支添加一个简单的Jenkinsfile,并使用Jenkinsfile执行您的Job DSL脚本.有关详细信息,请参见在管道脚本中使用Job DSL .这将需要最少的编码,但是我认为必须克隆每个存储库才能正常工作,因为Job DSL文件必须在文件系统上可用.

As a workaround you can use the Pipeline Multibranch Plugin and create a multibranch project for each of your repositories. You must then add a simple Jenkinsfile to each repo/branch and use the Jenkinsfile to execute your Job DSL scripts. See Use Job DSL in Pipeline scripts for details. This would require minimal coding, but I think each repo must be cloned for this to work because the Job DSL files must be available on the file system.

您可以使用Job DSL创建多分支作业,请参见 multibranchPipelineJob 在API查看器中.这将是您的根"种子工作.

You can use Job DSL to create the multibranch jobs, see multibranchPipelineJob in the API viewer. This would be your "root" seed job.

如果您的存储库托管在GitHub上,则还可以签出

If your repos are hosted on GitHub, you can also checkout the GitHub Organization Folder Plugin. With that plugin you must only create one job for each organization instead of multiple multibranch jobs.

这篇关于一个种子作业可以处理来自多个存储库的DSL吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆