Jenkins种子作业仅执行自上次运行以来修改的DSL脚本? [英] Jenkins seed job that executes only DSL scripts modified since the last run?

查看:77
本文介绍了Jenkins种子作业仅执行自上次运行以来修改的DSL脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个源代码存储库,其中包含Jenkins构建的各种代码,并且在Jenkins作业和源存储库之间是一对一的映射.与此分开的是,我有一个 single 存储库,其中包含Job DSL脚本,用于创建/更新用于构建其他存储库的Jenkins作业.情况看起来像这样:

I have several source code repositories containing various bits of code built by Jenkins, with a one-to-one mapping between Jenkins jobs and source repositories. Separate from these, I have a single repository containing Job DSL scripts for creating/updating the Jenkins jobs that build the other repos. The situation looks something like this:

我希望找到一种方法,将Job DSL脚本存储在代码旁边的各个源存储库中,并且有一个种子作业,该种子作业将由向以下对象的 any 的推送通知触发其他存储库.不幸的是,目前似乎还没有很好的支持(请参见此问题的已接受答案).鉴于此,现在看来,将所有DSL放在一个单独的单独的存储库中,似乎是最简单的,然后将推送通知到该存储库触发对groovy脚本的重新处理.或多或少,一切都很好.

I had hoped to find a way to store the Job DSL scripts inside the individual source repositories, right alongside the code, and have a single seed job that would be triggered by push notifications to any of the other repositories. Unfortunately, it appears that this is currently not well supported (see the accepted answer to this question). Given that, it seems simplest for now to just leave all the DSLs in a single, separate repository, and let push notifications to that repository trigger reprocessing of the groovy scripts. And it all works fine, more-or-less.

那是说,我有点担心种子作业在被触发时会重新运行所有DSL脚本,而不是仅重新运行那些已经实际更改过的DSL脚本.(老实说,我不确定这是否是一个问题",我只是担心以后会导致令人惊讶的行为.)

That said, I'm slightly concerned that the seed job—when triggered—re-runs all of the DSL scripts, rather than only those that have actually changed. (I'm honestly not sure whether this is a 'problem', per se, I just worry that it could lead to surprising behavior later on.)

是否可以通过某种方式重组种子作业,使其仅重新运行由触发生成的提交修改的脚本?或者...这值得担心吗?

Is there some way I can restructure the seed job so that it only re-runs scripts modified by the commit that triggered the build? Or... is this not worth worrying about?

推荐答案

Job DSL仅在生成的配置发生更改时才更新作业.它将生成的XML与现有配置进行比较,以查看是否需要更新.参见

Job DSL will only update a job if the generated config changes. It compares the generated XML with the existing config to see if an update is necessary. See JenkinsJobManagement.java. So if you do not change jobs manually or run malicious plugins that modify the job's config in the background, there should be no problem when re-running scripts.

并且Job DSL在运行多个脚本时会重用Groovy脚本引擎,因此对性能的影响应该很小.参见

And Job DSL reuses the Groovy script engine when running multiple scripts, so the performance impact should be low. See DslScriptLoader.groovy.

因此,如果您的脚本没有副作用(例如进行REST调用或修改文件系统),那么即使不必要也可以重新运行脚本.

So if your scripts have no side effects (e.g. making REST calls or modifying the file system), then it should be no problem to re-run scripts even if unnecessary.

这篇关于Jenkins种子作业仅执行自上次运行以来修改的DSL脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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