Replace classpath of a running Groovy Script (Jenkins Pipeline script)

耗尽温柔 提交于 2019-12-08 08:43:28

问题


In Jenkins Pipeline we have a CpsGroovyScript executed by CPSGroovyShell with a custom classpath which is appended with path to Global Library location.

In order to be able to test my changes before making them available for all the Pipelines on my Jenkins instance I want to override classpath by unloading the classes and modifying the script's classpath from itself in runtime.

My idea is to prepend current classpath with a new location so that changed classes found first. this.class.classLoader.addURL() is great but the new path goes to the end of classpath.

.../src - this is root of current production code, it's in classpath by default .../branch-src - this is root of my changed code, I want it to be used instead of .../src

For instance I want class .../src/com/foo/Bar.groovy to be overridden by .../branch-src/com/foo/Bar.groovy when I call import com.foo.Bar or new com.foo.Bar()

If this can't work at all is there any other hack, i.e. to completely replace original classpath, or to replace the whole classloader, whatever.

来源:https://stackoverflow.com/questions/35637833/replace-classpath-of-a-running-groovy-script-jenkins-pipeline-script

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