以编程方式获取插件的Jenkins配置 [英] Programmatically getting Jenkins configuration for a plugin

查看:151
本文介绍了以编程方式获取插件的Jenkins配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为Groovy控制台中具有Groovy脚本的插件获取(并希望更改)Jenkins配置.我的特定示例是尝试更改ssh发行插件的多个IP地址.通过命令行(编辑xml)很容易做到,但是经过数小时的努力之后,我仍然想通过groovy控制台找到它的实现方式,除了启迪,别无其他原因.我浏览了Jenkins API javadoc,但无济于事.

I'm trying to get (and hopefully change) the Jenkins configuration for a plugin with a Groovy script inside the Groovy console. My specific example is to try to change multiple IP addresses for the publish-over-ssh plugin. It's pretty easy to do via the command line (editing the xml), but after hours of struggling with it, I'd still like to find how it would be done via the groovy console, for no other reason than the enlightenment. I've looked through the Jenkins API javadoc, but to no avail.

如何在Jenkins控制台中查找/更改插件的全局配置?

How can I find/change the global configuration for a plugin inside the Jenkins console?

推荐答案

在这里是开始搜索的好地方:

Here is a good place to start searching:

>: //github.com/jenkinsci/publish-over-ssh-plugin/tree/master/src/main/java/jenkins/plugins/publish_over_ssh

以下是添加主机的示例:

Here is an example of adding a host:

import jenkins.model.*
import jenkins.plugins.publish_over_ssh.BapSshHostConfiguration
def inst = Jenkins.getInstance()
def publish_ssh = inst.getDescriptor("jenkins.plugins.publish_over_ssh.BapSshPublisherPlugin")
def configuration = new BapSshHostConfiguration(name,
  hostname,
  username,
  encryptedPassword,
  remoteRootDir,
  port,
  timeout,
  overrideKey,
  keyPath,
  key,
  disableExec
)
publish_ssh.addHostConfiguration(configuration)
publish_ssh.save()

在这里我们可以看到几个有用的功能:

Here we can see a couple helpful functions:

https://github.com/jenkinsci/publish-over-ssh-plugin/blob/master/src/main/java/jenkins/plugins/publish_over_ssh/descriptor/BapSshPublisherPluginDescriptor.java

  • getHostConfigurations()
  • removeHostConfiguration(最终字符串名称)

应该是您要做的所有信息,加油!

Should be all the info you need to do it, cheers!

这篇关于以编程方式获取插件的Jenkins配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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