0

I'm putting together some spock tests for a Jenkins plugin and along the way I want to check the build variables match one of some valid ones. These are coming from a MatrixProject

but how do I do that?

I have this but it looks a bit clunky but does work

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'])
}

Edit this is the spock spec for the Jenkins job-dsl Matrix Job plugin I'd like useful tests for

    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
    }
KeepCalmAndCarryOn
  • 8,817
  • 2
  • 32
  • 47

1 Answers1

3

Following code should work. If You expect any further simplifications it would be easier to share more code.

gen_build.getRuns.every { it.buildVariables in [[axis1: 'textz', axis2: 'text1'],[axis1: 'textz', axis2: 'text2'],[axis1: 'texty', axis2: 'text2']]}

You can also revert the assertion:

[[axis1: 'textz', axis2: 'text1'],[axis1: 'textz', axis2: 'text2'],[axis1: 'texty', axis2: 'text2']].containsAll(gen_build.getRuns*.buildVariables)
Opal
  • 81,889
  • 28
  • 189
  • 210