tr4pt tr4pt - 1 year ago 216
Groovy Question

How to set Jenkins JDK/Environment before deployment?

we want to provide an auto-installer for my company. So that the developers do not have to set up their workbench with a very long installation guide.
We managed to provide 90%.

Last week we received an email that we should configure Jenkins during the installation.
The first part of configuring the Proxy Setting is via a groovy script.

Groovy file:

pc = new hudson.ProxyConfiguration(name, port, userName, password, noProxyHost);
jenkins.model.Jenkins.instance.proxy = pc;
println "Jenkins-Proxy settings updated!


type set setJenkinsProxy.groovy | java -jar jenkins-cli.jar -s
http://localhost:8080/jenkins groovy =

The next part is to set the already installed JDK.
First thought was to use a groovy script to set the JDK.

Groovy file:

jdk = new hudson.model.JDK(name, home, list);
jdklist = []
jenkins.model.Jenkins.instance.JDKs = jdk;
println "JDK settings updated!

Even with a runnable .jar file, that will use the jenkins-cli.jar, it didn't work.


public static void main(String[] args) {

JDK jdk = new JDK(args[0], args[1]);

List<JDK> jdklist = new ArrayList<JDK>();
jenkins.model.Jenkins.jdks = jdklist;

System.out.println("Jenkins JDK set!");


Is there a proper way to set this Environment? I would really appreciate any way of help.

Would like to set Jenkins Location as well as Email- Notification too.

Answer Source

I finally found something to set the LocationConfiguration in Jenkins after the installation. So if anyone need it, this is the groovy script executable with jenkins-cli.jar

liste = new File('filename to read from').readLines()

jlc = new jenkins.model.JenkinsLocationConfiguration();
println jlc.getUrl()
println jlc.getAdminAddress()
jlc.setUrl("http://" + liste[0] + ":8080/jenkins/");

println ("Set url to: http://" + liste[0] + ":8080/jenkins/")
println ("Set AdminAddress to: " + liste[1])
println "JenkinsLocation updated!"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download