除了job-dsl-gradle-example中的示例之外,您还可以更进一步,为单个文件或作业编写测试。例如,假设您在Jobs / deployJob.groovy中有一个作业配置文件
import javaposse.jobdsl.dsl.DslscriptLoaderimport javaposse.jobdsl.dsl.MemoryJobManagementimport javaposse.jobdsl.dsl.scriptRequestimport spock.lang.Specificationclass TestDeployJobs extends Specification { def 'test basic job configuration'() { given: URL scriptURL = new File('jobs').toURI().toURL() scriptRequest scriptRequest = new scriptRequest('deployJob.groovy', null, scriptURL) MemoryJobManagement jobManagement = new MemoryJobManagement() when: DslscriptLoader.runDslEngine(scriptRequest, jobManagement) then: jobManagement.savedConfigs.each { String name, String xml -> with(new XmlParser().parse(new StringReader(xml))) { // Make sure jobs only run manually triggers.'hudson.triggers.TimerTrigger'.spec.text().isEmpty() // only deploy every environment once at a time concurrentBuild.text().equals('false') // do a workspace cleanup buildWrappers.'hudson.plugins.ws__cleanup.PreBuildCleanup' // make sure masked passwords are active !buildWrappers.'com.michelin.cio.hudson.plugins.maskpasswords.MaskPasswordsBuildWrapper'.isEmpty() } } }}这样,您便可以遍历要确保设置所有正确值的每个XML节点。



