jenkins:通过Groovy API设置根URL [英] jenkins: setting root url via Groovy API

查看:194
本文介绍了jenkins:通过Groovy API设置根URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过Groovy API更新Jenkins的根URL,因此我可以编写Jenkins主服务器部署脚本,而无需手动输入(此外:为什么构建/开发/自动化社区中的工具像Jenkins一样受欢迎如此抵制自动化?)

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?)

基于此文档,我相信我应该能够在脚本控制台中使用以下脚本来更新URL.

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())

简而言之,这将实例化JenkinsLocationConfiguration对象;用所需的值http://jenkins.my-org.com:8080/调用设置器setUrl;并打印出新网址以确认其已更改.

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.

println语句显示我期望的结果,但是此后,通过Web界面在"Manage Jenkins"->"Configure System"->"Jenkins URL"上可见的值具有不是已按预期更新.

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.

我担心Jenkins无法正确更新该值,这可能会导致在与外部API通信时出现问题.

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

这是修复Jenkins根URL的有效方法吗?如果没有,那是什么?否则,为什么更改没有反映在配置页面上?

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?

推荐答案

您正在创建一个新的JenkinsLocationConfiguration对象,并更新该新对象,而不是正在使用的现有对象

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

使用

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

要从全局jenkins配置中获取一个,请对其进行更新并保存配置描述符.

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

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

这篇关于jenkins:通过Groovy API设置根URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆