DSL Script as a groovy variable ?

643 views
Skip to first unread message

arjun...@gmail.com

unread,
Feb 23, 2016, 11:23:46 AM2/23/16
to job-dsl-plugin

I'm not sure if this is a job dsl or a groovy question. It will be great if I can get some help.  I have used string builder functions to build the jobdsl code and stored it in a variable. How do I execute/evaluate/use (not sure what the exact term is) that variable now ?

This is what my variable/string looks something like this - 

 

jobexample = """ job("asd") { 

                                parameteres {

                                     stringParam('branch','master')

                                }

                            } """ 


Any help would be appreciated. 


-Arjun

Victor Martinez

unread,
Feb 23, 2016, 11:55:28 AM2/23/16
to job-dsl-plugin
That-s a multiline variable you can see further examples in the wiki:

What do you try to accomplish?

Cheers

arjun...@gmail.com

unread,
Feb 23, 2016, 12:37:09 PM2/23/16
to job-dsl-plugin

This is the DSL script I'm trying process to create a simple jenkins job. 


def jobtemplate=""" job("test") {

              parameters {

              stringParam('branch', 'master')

              }

           } """

GroovyShell shell = new GroovyShell()

shell.evaluate(jobtemplate) 


This is the error I'm getting while running the build - 

ERROR: (Script1.groovy, line 1) No signature of method: Script1.job() is applicable for argument types: (java.lang.String, Script1$_run_closure1) values: [test, Script1$_run_closure1@24478fa]
Possible solutions: run(), run(), any(), wait(), find(), grep()
Finished: FAILURE

PS: I haven't copied my entire job dsl script but this is just to give you an idea of the issue I'm facing. The reason why I'm using variables is to avoid writing redundant code. I have to create multiple jobs with the same parameters , config and everything except for the post build step. 

-Arjun

Victor Martinez

unread,
Feb 23, 2016, 5:38:47 PM2/23/16
to job-dsl-plugin
If you want to validate your jobs setup and reuse your code then it's worth if you look at:
- https://github.com/sheehan/job-dsl-gradle-example  might be a great start point, since you can reuse part of your jobs based on some Classes and test them locally via gradle

In your case you are trying to evaluate a DSL which it's not part of that particular GroovyShell, so look at the above urls.

Cheers
Reply all
Reply to author
Forward
0 new messages