gradle test failing after adding managed script

48 views
Skip to first unread message

Eric Ackerson

unread,
Jun 1, 2016, 8:01:39 PM6/1/16
to job-dsl-plugin
I have recently added jobs to both add a managed script, and call the same managed script from within several jobs.  The jobs work as expected when called from jenkins, however when calling './gradlew test' I get the following error:

Expected no exception to be thrown, but got 'javaposse.jobdsl.dsl.DslScriptException'
	at spock.lang.Specification.noExceptionThrown(Specification.java:118)
	at com.rally.devops.jenkins.job.JobScriptsSpec.test script #file.name(JobScriptsSpec.groovy:27)
Caused by: javaposse.jobdsl.dsl.DslScriptException: (BuildReleaseLib.groovy, line 62) managed script with name 'semver' not found

The test looks like:
 
class JobScriptsSpec extends Specification {

@Unroll
void 'test script #file.name'(File file) {
given:
JobManagement jm = new MemoryJobManagement()

when:
DslScriptLoader.runDslEngine file.text, jm

then:
noExceptionThrown()

where:
file << jobFiles
}

static List<File> getJobFiles() {
List<File> files = []
new File('jobs').eachFileRecurse(FileType.FILES) {
if (it.name.endsWith('.groovy')) {
files << it
}
}
files
}
}

Daniel Spilker

unread,
Jun 14, 2016, 4:48:39 PM6/14/16
to job-dsl...@googlegroups.com
MemoryJobManagement does not keep state between test cases, so if you create the managed script in one DSL script and use it from another, the test will fail.

If that's the case you can share the JobManagement object between test cases. See "Sharing of Objects between Iterations" in https://spockframework.github.io/spock/docs/1.0/data_driven_testing.html

Daniel

--
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/24100c2f-c38a-4ac3-842c-8d19428f1d1d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Eric Ackerson

unread,
Jun 24, 2016, 10:03:36 AM6/24/16
to job-dsl-plugin
Awesome, that's fixed it for me, thanks!
Reply all
Reply to author
Forward
0 new messages