Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins Groovy Postbuild use static file instead of script

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 24x7 so finding a window when I can restart Jenkins or reload the config is problematic.

Thanks!

like image 703
JamesE Avatar asked Dec 26 '22 13:12

JamesE


1 Answers

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.

like image 56
Ivan Avatar answered Feb 07 '23 08:02

Ivan