Hi J-L,

 I've just seen your jobFramework class and I guess you don't need to use 
the configure closure 
<https://github.com/jenkinsci/job-dsl-plugin/wiki/The-Configure-Block> 
unless you those plugins are not supported by JobDSL, otherwise it's worth 
using the DSL syntax, for instance:
- 
https://jenkinsci.github.io/job-dsl-plugin/#method/javaposse.jobdsl.dsl.helpers.step.StepContext.environmentVariables

There are some interesting urls/projects:
- 
https://github.com/jenkinsci/job-dsl-plugin/wiki/Real-World-Examples#import-other-files-ie-with-class-definitions-into-your-script
- https://github.com/sheehan/job-dsl-gradle-example (this is my favourite 
one)

If you would like to use the configure closure anyway, use 
the http://job-dsl.herokuapp.com/ then you will be able to understand how 
your snippet is converted to XML and from there you could create your 
specific configure closure. the below DSL produce the same Job

freeStyleJob("my_job")
{
    environmentVariables {
        env('TOTO','TITI')
    }
}

freeStyleJob("my_job") {
    configure { project ->
        def properties = project / 'properties' 
        properties << EnvInjectJobProperty {
            info {
                propertiesContent('TOTO=TITI')
                loadFilesFromMaster(false)
            }
            on(true)
            keepJenkinsSystemVariables(true)
            keepBuildVariables(true)
            overrideBuildParameters(false)
            contributors('')
        }
    }
}


Finally, if you use JobDSL version 1.46+ then you can use the autogenerated 
DSL 
<https://github.com/jenkinsci/job-dsl-plugin/wiki/Automatically-Generated-DSL> 
and 
get rid off the configure closure.

I hope it helps,

Cheers

On Wednesday, 2 November 2016 17:38:50 UTC, JL 6BerYeti wrote:
>
> Quite new to Job DSL, I am running some tests and trias.
> I currently try to factorize some common job configuration part in a 
> library I can reuse within each job.
> I know how to do that with DSL, but I face out a problem with adding an 
> env var.
>
> I have this code which run ok :
>
> class jobFramework {
>    static commonConf(dslFactory) {
>        dslFactory.configure { project ->
>            project / 'buildWrappers' {
>                'hudson.plugins.ws__cleanup.PreBuildCleanup'{
>                    'deleteDirs'(false)
>                }
>                'trigger'{
>                    'cron'('*,*,H/4,*')
>                }
>
>            }
>            project / 'logRotator' {
>                 'daysToKeep'('10')
>                 'numToKeep'('-1')
>                 'artifactDaysToKeep'('12')
>                 'artifactNumToKeep'('-1')
>             }
>        }
>    }
> }
>
> freeStyleJob("my_job")
> {
>     environmentVariables {
>         env('TOTO','TITI')
>     }
>     jobFramework.commonConf(it)
> }
>
> Now I would like to put the env var definition into the jobFramework class.
> But trying the following lines :
>            project / 'environmentVariables' {
>                'env'('TOTO','TITI')
>            }
> I obtain the following error :
> groovy.lang.MissingMethodException: No signature of method: 
> groovy.util.NodeBuilder.env() is applicable for argument types: 
> (java.lang.String, java.lang.String) values: [TOTO, TITI]
> Possible solutions: any(), find(), any(groovy.lang.Closure), wait(), 
> every(), dump()
> at jobFramework$_commonConf_closure1$_closure4.doCall(script:20)
> at jobFramework$_commonConf_closure1$_closure4.doCall(script)
> at 
> javaposse.jobdsl.dsl.MissingPropertyToStringDelegate.methodMissing(MissingPropertyToStringDelegate.groovy:39)
> at 
> javaposse.jobdsl.dsl.MissingPropertyToStringDelegate.invokeMethod(MissingPropertyToStringDelegate.groovy)
> at jobFramework$_commonConf_closure1.doCall(script:19)
> ...
> where 10 is the line number of the lines related to env vars.
>
> So... after several trials, I am quite lost...
>
> If someone cold help, thanks a lot !
>
> Best Regards
> J-L
>

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/ef43b886-54b1-4cb5-af09-9801063f4a1b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to