In our Jenkinsfile we have a lot of parameters (parameterized build) and in this case I want to check if each parameter is toggled and act on that. These parameters have similar names but end with a different decimal, so I would like to iterate over them to achieve this.
I have something like:
if ("${TEST_00}" == "true") { testTasksToRun.add(testsList[0]) }
if ("${TEST_01}" == "true") { testTasksToRun.add(testsList[1]) }
if ("${TEST_02}" == "true") { testTasksToRun.add(testsList[2]) }
if ("${TEST_03}" == "true") { testTasksToRun.add(testsList[3]) }
if ("${TEST_04}" == "true") { testTasksToRun.add(testsList[4]) }
if ("${TEST_05}" == "true") { testTasksToRun.add(testsList[5]) }
But I would like to have something like:
for(int i=0; i<testsList.size(); i++) {
if ("${TEST_0${i}}" == "true") {
testTasksToRun.add(testsList[i])
}
}
I tried to search for solutions and experimented on the GroovyConsole but didn't manage to get anything to work. Looks like it has something to do with "binding", but I am not familiar with that.