Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jenkins: setting root url via Groovy API

Tags:

jenkins

groovy

I'm trying to update Jenkins' root URL via the Groovy API, so I can script the deployment of a Jenkins master without manual input (aside: why is a tool as popular with the build/devops/automation community as Jenkins so resistant to automation?)

Based on this documentation, I believe I should be able to update the URL using the following script in the Script Console.

import jenkins.model.JenkinsLocationConfiguration
jlc = new jenkins.model.JenkinsLocationConfiguration()
jlc.setUrl("http://jenkins.my-org.com:8080/") 
println(jlc.getUrl())

Briefly, this instantiates a JenkinsLocationConfiguration object; calls the setter setUrl with the desired value, http://jenkins.my-org.com:8080/; and prints out the new URL to confirm that it has changed.

The println statement prints what I expect it to, but following this, the value visible through the web interface at "Manage Jenkins" -> "Configure System" -> "Jenkins URL" has not updated as I expected.

I'm concerned that the value hasn't been update properly by Jenkins, which might lead to problems when communicating with external APIs.

Is this a valid way to fix the Jenkins root URL? If not, what is? Otherwise, why isn't the change being reflected in the config page?

like image 509
laffoyb Avatar asked May 20 '15 16:05

laffoyb


1 Answers

You are creating a new JenkinsLocationConfiguration object, and updating the new one, not the existing one being used

use

jlc = JenkinsLocationConfiguration.get()
// ...
jlc.save() 

to get the one from the global jenkins configuration, update it and save the config descriptor back.

see : https://github.com/jenkinsci/jenkins/blob/master/core/src/main/java/jenkins/model/JenkinsLocationConfiguration.java

like image 126
Peter Tillemans Avatar answered Sep 20 '22 23:09

Peter Tillemans