首页 > 解决方案 > 如何在测试工具中模拟 Jenkins 作业参数?

问题描述

我正在尝试使用测试工具来测试作业 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”设置为不同的值,然后将在实际的种子作业配置中进行配置?

标签: jenkinsjenkins-groovyjenkins-job-dsl

解决方案


推荐阅读