我正在为 Jenkins 插件整理一些 spock 测试,并且在此过程中我想检查构建变量是否与一些有效变量之一匹配。这些来自 MatrixProject
但我该怎么做?
我有这个,但它看起来有点笨重,但确实有效
gen_build.getRuns.every(){
it.getBuildVariables().equals([axis1: 'textz', axis2: 'text1']) ||
it.getBuildVariables().equals([axis1: 'textz', axis2: 'text2']) ||
it.getBuildVariables().equals([axis1: 'texty', axis2: 'text2'])
}
编辑这是 Jenkins job-dsl Matrix Job 插件的 spock 规范我想要有用的测试
def 'CombinationFilter'() {
given:
def job = configure( $/
job(type:MatrixJob){
name "generated"
axis{
text("axis1", ["textz", "texty"])
text("axis2", ["text1", "text2"])
}
steps{
shell('return 255')
}
combinationFilter("axis1=='textz' || axis2=='text2'")
sequential(false)
}
/$)
when:
def job_build = job.scheduleBuild2(0).get()
def gen = rule.getInstance().getItem("generated")
def gen_build = gen.scheduleBuild2(0).get()
def gen_runs = gen_build.getRuns()
then:
job_build.logFile.text.contains("SUCCESS")
gen_build.logFile.text.contains("FAILURE")
gen_runs.every(){it.logFile.text.contains("FAILURE")}
gen_runs.every(){it.getBuildVariables().equals([axis1: 'textz', axis2: 'text1']) || it.getBuildVariables().equals([axis1: 'textz', axis2: 'text2']) || it.getBuildVariables().equals([axis1: 'texty', axis2: 'text2'])}
gen_runs.size() == 3
}