Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically getting Jenkins configuration for a plugin

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?

like image 498
TheDauthi Avatar asked Mar 16 '15 19:03

TheDauthi


Video Answer


1 Answers

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!

like image 122
a2tide Avatar answered Sep 28 '22 08:09

a2tide