Issue
I have a Jenkins choice parameter which is integer value. I need to loop through the parameter value in my Jenkins File to run a function [i] times.
Say for Ex: Choice Parameter has ['1','2','3','4'] in drop down. If I chooses 4, the loop should go through 4 times.
But my below code only displays I choose in the parameter which is '4' while echoing it. Could someone help me in loop through.
script {
def loop_value = "${params.choiceparameter}"
loop_value.each() {
echo it
}
}
Solution
Use it like this:
pipeline {
agent any
parameters {
choice choices: ['1', '2', '3', '4', '5'], description: '', name: 'choiceParameter'
}
stages {
stage("stage1") {
steps {
script {
for (i = 0; i < params.choiceParameter.toInteger(); i ++) {
print(i)
}
}
}
}
}
}
Answered By - Stefano Martins