Set authenticationToken from credentials

33 views
Skip to first unread message

Eberhard Beilharz

unread,
Sep 11, 2017, 12:33:14 PM9/11/17
to job-dsl-plugin


How can I set the authenticationToken from a credential? The doc suggest not to use a hard-coded token but doesn't give an example and I haven't been able to find how to do it.

My current code looks like this:

...
       wrappers {
            credentialsBinding {
                string('myToken', 'trigger-token')
            }
        }

        authenticationToken("${myToken}")
...

However this throws a groovy exception:

Expected no exception to be thrown, but got 'javaposse.jobdsl.dsl.DslScriptException'
	at spock.lang.Specification.noExceptionThrown(Specification.java:118)
	at utilities.JobScriptsSpec.test script #file.name(JobScriptsSpec.groovy:50)
Caused by: javaposse.jobdsl.dsl.DslScriptException: (script, line 468) No such property: myToken for class: javaposse.jobdsl.dsl.jobs.FreeStyleJob
	at javaposse.jobdsl.dsl.AbstractDslScriptLoader.runScriptEngine(AbstractDslScriptLoader.groovy:117)
	at javaposse.jobdsl.dsl.AbstractDslScriptLoader.runScripts_closure1(AbstractDslScriptLoader.groovy:58)
	at groovy.lang.Closure.call(Closure.java:414)
	at groovy.lang.Closure.call(Closure.java:430)
	at javaposse.jobdsl.dsl.AbstractDslScriptLoader.runScripts(AbstractDslScriptLoader.groovy:45)
	at javaposse.jobdsl.dsl.AbstractDslScriptLoader.runScript(AbstractDslScriptLoader.groovy:83)
	at utilities.JobScriptsSpec.test script #file.name(JobScriptsSpec.groovy:46)
Caused by: groovy.lang.MissingPropertyException: No such property: myToken for class: javaposse.jobdsl.dsl.jobs.FreeStyleJob
	at script.run_closure1(script:468)
	at groovy.lang.Closure.call(Closure.java:414)
	at groovy.lang.Closure.call(Closure.java:430)
	at javaposse.jobdsl.dsl.JobParent.processItem(JobParent.groovy:117)
	at javaposse.jobdsl.dsl.JobParent.freeStyleJob(JobParent.groovy:49)
	at script.run(script:435)
	at javaposse.jobdsl.dsl.AbstractDslScriptLoader.runScriptEngine(AbstractDslScriptLoader.groovy:111)
	... 6 more

I also tried authenticationToken('${myToken}') and authenticationToken(bindings.variable.myToken). This doesn't give an error but doesn't work either - maybe because the trigger doesn't accept environment variables?

How is this supposed to work?

Thanks,
Eberhard

Eberhard Beilharz

unread,
Sep 12, 2017, 5:01:50 AM9/12/17
to job-dsl-plugin
Answering my own question:

in the groovy script you only put:

...
        authenticationToken("${myToken}")
...

The binding of myToken to the secret text credential needs to happen in the seed job that processes the groovy script!


Eberhard Beilharz

unread,
Sep 12, 2017, 5:11:36 AM9/12/17
to job-dsl-plugin
And in case you want to build locally you'll have to use the `binding.variables.*` notation:

...
        authenticationToken(binding.variables.myToken)
...
Reply all
Reply to author
Forward
0 new messages