Jenkins Groovy Postbuild use static file instead of script

groovyJenkinsjenkins-plugins

Is it possible to load an external groovy script into the groovy post build plugin instead of pasting the script content into each job? We have approximately 200 jobs so updating them all is rather time consuming. I know that I could write a script to update the config files directly (as in this post: Add Jenkins Groovy Postbuild step to all jobs), but these jobs run 24×7 so finding a window when I can restart Jenkins or reload the config is problematic.

Thanks!

Best Answer

Just put the following in the "Groovy script:" field:

evaluate(new File("... groovy script file name ..."));

Also, you might want to go even further. What if script name or path changes? Using Template plugin you can create a single "template" job, define call to groovy script (above line) in there, and in all jobs that need it add post-build action called "Use publishers from another project" referencing this template project.

Related Topic