Fwd: Using StaplerRequest to configure a plugin?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Fwd: Using StaplerRequest to configure a plugin?

Guy Matz
Is this an appropriate place to ask this kind of question?

---------- Forwarded message ----------
From: Guy Matz <[hidden email]>
Date: Tue, Mar 6, 2018 at 5:34 PM
Subject: Using StaplerRequest to configure a plugin?
To: [hidden email]


Hi!  Does anyone know how to automate the configuration of a plugin using a StaplerRequest object?  I'm trying to configure scm-sync-configuration with:

import net.sf.json.JSONObject
import org.kohsuke.stapler.StaplerRequest
import hudson.plugins.scm_sync_configuration.ScmSyncConfigurationPlugin

def params = [ 
                noUserCommitMessage: false,
                displayStatus: true,
                scm: 'hudson.plugins.scm_sync_configuration.scms.ScmSyncGitSCM',
                gitRepositoryUrl: '[hidden email]:GroupM-mPlatform/ci.git',
                commitMessagePattern: '[message]',
                manualSynchronizationIncludes: 'asdfasdf'
]

def JSONObject formData = [ params ] as JSONObject

scm = new ScmSyncConfigurationPlugin().getInstance()
println("SCMs? ${scm.getScms()}")

StaplerRequest req = [
  getParameter: { name -> 
    // println(params[name])
    params[name]
  }
] as org.kohsuke.stapler.StaplerRequest 

scm.configure(req, formData)

It seems to almost work a little - uncommenting "println(params[name])" tells me that it's getting processed a bit - but then it bombs with:

java.lang.UnsupportedOperationException
at org.codehaus.groovy.runtime.ConvertedMap.invokeCustom(ConvertedMap.java:52)
at org.codehaus.groovy.runtime.ConversionHandler.invoke(ConversionHandler.java:124)
at com.sun.proxy.$Proxy51.getParameterValues(Unknown Source)
at hudson.plugins.scm_sync_configuration.ScmSyncConfigurationPlugin.configure(ScmSyncConfigurationPlugin.java:218)
at hudson.plugins.scm_sync_configuration.ScmSyncConfigurationPlugin$configure.call(Unknown Source)

The source at line 218 of ScmSyncConfigurationPlugin is:
if(req.getParameterValues("manualSynchronizationIncludes") != null){ 
...
}

Any thoughts out there?  :-(

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CABnTgtVjWvzp7UHcUftVAtNbY48OdrWeNn4wOQJwZj6Kkqj66A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Using StaplerRequest to configure a plugin?

Daniel Beck

> On 7. Mar 2018, at 15:49, Guy Matz <[hidden email]> wrote:
>
> Is this an appropriate place to ask this kind of question?

Looks like a user question but you're deep enough in the guts of Jenkins to qualify for this list IMO.

Regarding your specific approach, you're implementing the single method `getParameter`, so the call to `getParameterValues` fails.

Note that you're probably more successful if you're planning to work with https://github.com/jenkinsci/configuration-as-code-plugin/ to configure your Jenkins once it's available :-)

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/7287B560-F0BF-41BC-B209-B9B6F7170D68%40beckweb.net.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Using StaplerRequest to configure a plugin?

Vlad Gorbunov
In reply to this post by Guy Matz
Try to use 

StaplerRequest req = org.kohsuke.stapler.Stapler.getCurrentRequest()


--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/98dcae4d-06db-4b7b-bf54-167acb1ef984%40googlegroups.com.