Details
-
Bug
-
Status: Resolved (View Workflow)
-
Minor
-
Resolution: Not A Defect
Description
When using a parallel step for an indexed loop, using the loop-iterator-index for internal usage results with wrong value (showing the max-index-value for all iterations).
A workaround for it is to set a local variable for saving the current iteration-index and use the local variable.
The following pipeline demonstrates the problem (the issue is demonstrated with the internal 'echo' steps):
pipeline { agent any stages { stage('Explore bug') { steps { script { int maxIndex1=3 def loopers1 = [:] for (int loopIndex1 = 0; loopIndex1 < maxIndex1; loopIndex1++) { echo "loopIndex1=${loopIndex1}" loopers1["loop-$\{loopIndex1}"] = { echo "loopIndex1=${loopIndex1}" } } parallel loopers1 } } } stage('Bug workaround') { steps { script { int maxIndex2=3 def loopers2 = [:] for (int loopIndex2 = 0; loopIndex2 < maxIndex2; loopIndex2++) { int index2=loopIndex2 echo "index2=${index2}" loopers2["loop-$\{index2}"] = { echo "index2=${index2}" } } parallel loopers2 } } } } }
Attachments
Activity
Field | Original Value | New Value |
---|---|---|
Description |
When using a parallel step for an indexed loop, using the loop-iterator-index for internal usage results with wrong value (showing the max-index-value for all iterations). A workaround for it is to set a local variable for saving the current iteration-index and use the local variable. The following pipeline demonstrates the problem (the issue is demonstrated with the internal 'echo' steps): {code:java} // code placeholder {code} pipeline \{ agent any stages \{ stage('Explore bug') \{ steps \{ script \{ int maxIndex1=3 def loopers1 = [:] for (int loopIndex1 = 0; loopIndex1 < maxIndex1; loopIndex1++) \{ echo "loopIndex1=$\{loopIndex1}" loopers1["loop-$\{loopIndex1}"] = \{ echo "loopIndex1=$\{loopIndex1}" } } parallel loopers1 } } } stage('Bug workaround') \{ steps \{ script \{ int maxIndex2=3 def loopers2 = [:] for (int loopIndex2 = 0; loopIndex2 < maxIndex2; loopIndex2++) \{ int index2=loopIndex2 echo "index2=$\{index2}" loopers2["loop-$\{index2}"] = \{ echo "index2=$\{index2}" } } parallel loopers2 } } } } } |
When using a parallel step for an indexed loop, using the loop-iterator-index for internal usage results with wrong value (showing the max-index-value for all iterations). A workaround for it is to set a local variable for saving the current iteration-index and use the local variable. The following pipeline demonstrates the problem (the issue is demonstrated with the internal 'echo' steps): {code:java} // code placeholder {code} pipeline \{ agent any stages \{ stage('Explore bug') \{ steps \{ script \{ int maxIndex1=3 def loopers1 = [:] for (int loopIndex1 = 0; loopIndex1 < maxIndex1; loopIndex1++) \{ echo "loopIndex1=$\{loopIndex1}" loopers1["loop-$\\{loopIndex1}"] = \{ echo "loopIndex1=$\{loopIndex1}" } } parallel loopers1 } } } stage('Bug workaround') \{ steps \{ script \{ int maxIndex2=3 def loopers2 = [:] for (int loopIndex2 = 0; loopIndex2 < maxIndex2; loopIndex2++) \{ int index2=loopIndex2 echo "index2=$\{index2}" loopers2["loop-$\\{index2}"] = \{ echo "index2=$\{index2}" } } parallel loopers2 } } } } } |
Description |
When using a parallel step for an indexed loop, using the loop-iterator-index for internal usage results with wrong value (showing the max-index-value for all iterations). A workaround for it is to set a local variable for saving the current iteration-index and use the local variable. The following pipeline demonstrates the problem (the issue is demonstrated with the internal 'echo' steps): {code:java} // code placeholder {code} pipeline \{ agent any stages \{ stage('Explore bug') \{ steps \{ script \{ int maxIndex1=3 def loopers1 = [:] for (int loopIndex1 = 0; loopIndex1 < maxIndex1; loopIndex1++) \{ echo "loopIndex1=$\{loopIndex1}" loopers1["loop-$\\{loopIndex1}"] = \{ echo "loopIndex1=$\{loopIndex1}" } } parallel loopers1 } } } stage('Bug workaround') \{ steps \{ script \{ int maxIndex2=3 def loopers2 = [:] for (int loopIndex2 = 0; loopIndex2 < maxIndex2; loopIndex2++) \{ int index2=loopIndex2 echo "index2=$\{index2}" loopers2["loop-$\\{index2}"] = \{ echo "index2=$\{index2}" } } parallel loopers2 } } } } } |
When using a parallel step for an indexed loop, using the loop-iterator-index for internal usage results with wrong value (showing the max-index-value for all iterations). A workaround for it is to set a local variable for saving the current iteration-index and use the local variable. The following pipeline demonstrates the problem (the issue is demonstrated with the internal 'echo' steps): {code:java} // code placeholder {code} pipeline \{ agent any stages \{ stage('Explore bug') \{ steps \{ script \{ int maxIndex1=3 def loopers1 = [:] for (int loopIndex1 = 0; loopIndex1 < maxIndex1; loopIndex1++) \{ echo "loopIndex1=$\{loopIndex1}" loopers1["loop-$\{loopIndex1}"] = \{ echo "loopIndex1=$\{loopIndex1}" } } parallel loopers1 } } } stage('Bug workaround') \{ steps \{ script \{ int maxIndex2=3 def loopers2 = [:] for (int loopIndex2 = 0; loopIndex2 < maxIndex2; loopIndex2++) \{ int index2=loopIndex2 echo "index2=$\{index2}" loopers2["loop-$\{index2}"] = \{ echo "index2=$\{index2}" } } parallel loopers2 } } } } } |
Description |
When using a parallel step for an indexed loop, using the loop-iterator-index for internal usage results with wrong value (showing the max-index-value for all iterations). A workaround for it is to set a local variable for saving the current iteration-index and use the local variable. The following pipeline demonstrates the problem (the issue is demonstrated with the internal 'echo' steps): {code:java} // code placeholder {code} pipeline \{ agent any stages \{ stage('Explore bug') \{ steps \{ script \{ int maxIndex1=3 def loopers1 = [:] for (int loopIndex1 = 0; loopIndex1 < maxIndex1; loopIndex1++) \{ echo "loopIndex1=$\{loopIndex1}" loopers1["loop-$\{loopIndex1}"] = \{ echo "loopIndex1=$\{loopIndex1}" } } parallel loopers1 } } } stage('Bug workaround') \{ steps \{ script \{ int maxIndex2=3 def loopers2 = [:] for (int loopIndex2 = 0; loopIndex2 < maxIndex2; loopIndex2++) \{ int index2=loopIndex2 echo "index2=$\{index2}" loopers2["loop-$\{index2}"] = \{ echo "index2=$\{index2}" } } parallel loopers2 } } } } } |
When using a parallel step for an indexed loop, using the loop-iterator-index for internal usage results with wrong value (showing the max-index-value for all iterations). A workaround for it is to set a local variable for saving the current iteration-index and use the local variable. The following pipeline demonstrates the problem (the issue is demonstrated with the internal 'echo' steps): {code:java} pipeline { agent any stages { stage('Explore bug') { steps { script { int maxIndex1=3 def loopers1 = [:] for (int loopIndex1 = 0; loopIndex1 < maxIndex1; loopIndex1++) { echo "loopIndex1=${loopIndex1}" loopers1["loop-$\{loopIndex1}"] = { echo "loopIndex1=${loopIndex1}" } } parallel loopers1 } } } stage('Bug workaround') { steps { script { int maxIndex2=3 def loopers2 = [:] for (int loopIndex2 = 0; loopIndex2 < maxIndex2; loopIndex2++) { int index2=loopIndex2 echo "index2=${index2}" loopers2["loop-$\{index2}"] = { echo "index2=${index2}" } } parallel loopers2 } } } } }{code} |
Component/s | workflow-cps-plugin [ 21713 ] | |
Component/s | pipeline [ 21692 ] |
Labels | parallel pipeline | parallel pipeline triaged-2018-11 |
Resolution | Not A Defect [ 7 ] | |
Status | Open [ 1 ] | Resolved [ 5 ] |