How to resolv a variable in job dsl groovy script part

1,840 views
Skip to first unread message

Jozsef Sin

unread,
Oct 4, 2016, 10:34:43 AM10/4/16
to job-dsl-plugin
Hi,

I trying to create a seed job but the groovy script part not generating properly.  
Here is an example. The generated job should resolv the $nodename variable in the groovy script part. How should i do?
Thanks!


NODES="node1,node2"
PROPFILES="default.properties"
def Nodes = "${NODES}".split(",")
def selected = "${PROPFILES}"

job('example') {
    description 'Example.'

 for( nodename in Nodes ) {
    parameters {
        activeChoiceReactiveReferenceParam('CONTENT') {
            description('Properties file!')
            omitValueField()
            choiceType('FORMATTED_HTML')
            groovyScript {
                script('''
String filePath = "/home/jenkins/pops/$nodename/"
String fileName = "${selected}"
String selectedProperties = new File(filePath+fileName).getText('UTF-8')
return "<textarea name=\\"value\\" rows=\\"10\\" cols=\\"100\\">${selectedProperties}</textarea>"
'''.stripIndent().trim())
                fallbackScript('"Error in script"')
            }
            referencedParameter('PROPFILES')
        }
    }
 } 
}

Victor Martinez

unread,
Oct 4, 2016, 1:01:40 PM10/4/16
to job-dsl-plugin
I believe thats not a dsl question but a groovy one:

Have you tried to use brackets with your variable name? ${variable} to interpolate that variable.

My two cents

Matt Sheehan

unread,
Oct 4, 2016, 3:15:22 PM10/4/16
to job-dsl...@googlegroups.com
You should use triple double-quotes instead of triple single-quotes if you want variables to be interpolated. But then you'll need to escape the variables you don't want to be interpolated by the DSL. Something like:

--
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-plugi...@googlegroups.com.
To post to this group, send email to job-dsl...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/job-dsl-plugin/946ca4cf-3229-48bf-8fe5-d9278a80bb26%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jozsef Sin

unread,
Oct 5, 2016, 5:13:07 AM10/5/16
to job-dsl-plugin
Ok ,thanks triple double-quotes works fine.
Reply all
Reply to author
Forward
0 new messages