简体   繁体   中英

Jenkins Execute Groovy Script Before Loading Plugins

I need to change some plugin config files before plugins are loaded. I looked into the init.groovy.d , however it seems to run Groovy scripts in that directory after plugins have been loaded and therefore would require a restart to apply. Is there a way to run Groovy scripts before Jenkins loads the plugins?

What you are requesting is not necessary. Generally, when adding plugins, they come unconfigured. Jenkins starts, loads the plugins, then you can configure via init.groovy , CasC , etc., similar to you adding via GUI (add, restart, configure).

We start w/war file, wrapper, init.groovy.d, plus a variant of the docker install_plugins.sh . Other than the war, the wrapper and wrapper.conf, install_plugins.sh and plugin list, and all the init scripts are controlled in a git repo, which we pull down. dumping the plugins into the plugins dir, then launch jenkins.sh .

The init.groovy runs automatically after initialization and configures all system, global, tools and plugins values, as well as credentials values, also creating/configuring nodes.

NB: best to use 1 init script per section or plugin as a failure in any init script will quietly fail, effectively skipping the rest of the script.

You may need to .save() after setting most parameters via init.goovy. Perhaps that's why you did not see the changes.

If you were really paranoid, you could first invoke Hudson.instance. doQuietDown() , which effective blocks the queue (multiple init.groovy scripts execute in lexical order ), do all the configurations, then invoke doCancelQuietDown() , but we'd had no issues w/o that.

This approach (init.groovy.d) works fine, but looking to switch to JCasC now that it's matured. CasC is a simpler to manage (again, using separate config files for each plugin) and read.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM