DSL groovy script for Dynamc choice parameters with script

609 views
Skip to first unread message

Sai Kishore

unread,
Dec 13, 2016, 8:53:34 AM12/13/16
to job-dsl-plugin
I have to use 

config.xml as shown below

<hudson.model.ParametersDefinitionProperty>
<parameterDefinitions>
<com.seitenbau.jenkins.plugins.dynamicparameter.ChoiceParameterDefinition plugin="dynamicp...@0.2.0">
<name>buildNumber</name>
<description/>
<__uuid>4aaea25b-f0d7-4a63-8779-66e05b68174e</__uuid>
<__remote>false</__remote>
<__script>
import hudson.model.* BUILD_JOB_NAME = "***" def getJobs() { def hi = Hudson.instance return hi.getItems(Job) } def getBuildJob() { def buildJob = null def jobs = getJobs() (jobs).each { job -> if (job.displayName == BUILD_JOB_NAME) { buildJob = job } } return buildJob } def getAllBuildNumbers(Job job) { def buildNumbers = [] (job.getBuilds()).each { build -> buildNumbers.add(build.number) } return buildNumbers } def buildJob = getBuildJob() return getAllBuildNumbers(buildJob)
</__script>
<__localBaseDirectory serialization="custom">
<hudson.FilePath>
<default>
<remote>/var/lib/jenkins/dynamic_parameter/classpath</remote>
</default>
<boolean>true</boolean>
</hudson.FilePath>
</__localBaseDirectory>
<__remoteBaseDirectory>dynamic_parameter_classpath</__remoteBaseDirectory>
<__classPath/>
<readonlyInputField>false</readonlyInputField>
</com.seitenbau.jenkins.plugins.dynamicparameter.ChoiceParameterDefinition>
<hudson.model.ChoiceParameterDefinition>
<name>***</name>
<description>Hostname</description>
<choices class="java.util.Arrays$ArrayList">
<a class="string-array">
<string>*****</string>
<string>*****</string>
</a>
</choices>
</hudson.model.ChoiceParameterDefinition>
</parameterDefinitions>
</hudson.model.ParametersDefinitionProperty>



I want to get this from dsl script, can any one help me to solve this issue
Capture.PNG

Victor Martinez

unread,
Dec 14, 2016, 4:31:44 AM12/14/16
to job-dsl-plugin
If you use the configure closure:

You can generate something like

job('your_job') {
    ...
    configure { project ->
        def properties = project / 'properties'
        def parameters = properties / 'hudson.model.ParametersDefinitionProperty' / 'parameterDefinitions'
        parameters << 'com.seitenbau.jenkins.plugins.dynamicparameter.ChoiceParameterDefinition' {
            name('buildNumber')
            description('... whatever ....')
            __script '''
              import hudson.model.* BUILD_JOB_NAME = "***" 
              def getJobs() { 
              ...
              }            
              '''.stripIndent().trim()
            __uuid('4aaea25b-f0d7-4a63-8779-66e05b68174e')
            __remote(false)
            '__localBaseDirectory'(serialization: 'custom') << 'hudson.FilePath' {
                'default' {
                    remote('/var/lib/jenkins/dynamic_parameter/classpath')
                }
                delegate.boolean(true)
            }
            __remoteBaseDirectory('dynamic_parameter_classpath')
            readonlyInputField(false)
            __classPath()
        }
    }
}


Although you can review whether you can use the automatically DSL:

Cheers

Sai Kishore

unread,
Dec 14, 2016, 8:10:49 AM12/14/16
to job-dsl...@googlegroups.com
Thank you for your help the code you gave is working fine...

I have one question ,I sthat UUID is unique and how it is generated?

Thanks
Sai kishore Amirishetty

--
You received this message because you are subscribed to the Google Groups "job-dsl-plugin" group.
To unsubscribe from this group and stop receiving emails from it, send an email to job-dsl-plugin+unsubscribe@googlegroups.com.
To post to this group, send email to job-dsl-plugin@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/job-dsl-plugin/50d86928-ce34-4560-8b97-d709fe8b004d%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Victor Martinez

unread,
Dec 14, 2016, 10:32:02 AM12/14/16
to job-dsl-plugin
No idea though, you will need to see how the choice parameter works internally

Cheers

Reply all
Reply to author
Forward
0 new messages