如何在测试工具中模拟Jenkins的工作参数?

时间:2020-07-22 18:07:06

标签: jenkins jenkins-groovy jenkins-job-dsl

我正在尝试使用测试工具来测试作业dsl脚本:https://github.com/testcookbook/jenkins_harness

种子Jenkins作业已为其配置了参数,可以在脚本中访问它们,例如“ $ {myparam}”

我还是像这样在spock中运行种子作业:

def 'test script #file.name'(File file) {
    given:
    def jobManagement = new JenkinsJobManagement(System.out, [:], new File('.'))
    def myparam = 'sldkjflsdkjfs'
    // this also doesn't work (No such property: myparam for class: script)
    jobManagement.parameters.put("myparam", 'sldfjlsdjflskdjf')

    when:
    new DslScriptLoader(jobManagement).runScript(file.text)

    then:
    noExceptionThrown()

    where:
    file << jobFiles // uses groovy's automatic getter => getJobFiles()
}

dsl脚本的加载方式不会选择“ myparam”。如何以及在哪里设置,以便可以在本地运行并将“ myparam”设置为不同的值,然后将在实际的种子作业配置中进行配置?

0 个答案:

没有答案