Programmatically getting Jenkins configuration for a plugin

旧城冷巷雨未停 提交于 2020-06-24 12:53:16

问题


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.

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


回答1:


Here is a good place to start searching:

https://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(final String name)

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



来源:https://stackoverflow.com/questions/29085710/programmatically-getting-jenkins-configuration-for-a-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!