Jenkins seed job that executes only DSL scripts modified since the last run?

人盡茶涼 提交于 2019-12-11 06:08:17

问题


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:

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.

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?


回答1:


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.

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

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.



来源:https://stackoverflow.com/questions/41706710/jenkins-seed-job-that-executes-only-dsl-scripts-modified-since-the-last-run

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!