-
Type:
Bug
-
Resolution: Unresolved
-
Priority:
Major
-
Component/s: pipeline
-
None
-
Environment:jenkins version 2.401.3
I encountered unexpected behavior when running a function in parallel.
My scenario:
Â
Â
pipeline { Â Â
stage('Some stage') { Â Â Â Â
steps { Â Â Â Â Â Â
script { Â Â Â Â Â Â Â Â
def awsActions[] Â Â Â Â Â Â Â Â
awsActions['ec2_A'] = { awsFunc('ec2_A') }
awsActions['ec2_B'] = { awsFunc('ec2_B') } Â Â Â Â Â Â Â Â
awsActions['ec2_C'] = { awsFunc('ec2_C') }
parallel awsActions
} Â Â Â Â
}
 }
}
def awsFunc(ec2) { Â Â
def counter = 0
 def id
while (counter < 5 && conditionNotMet) {
id = run aws command to getinstance id ${ec2} Â Â Â Â
counter++ Â Â Â Â
echo "counter = ${counter}"
echo "id = ${id}" Â Â
}
}
Â
Â
Log results are as follows:
ec2_A:
counter = 1
id = ec2_A-id
counter = 3
id =ec2_B-id
Â
ec2_B:
counter = 2
id = ec2_A-id
counter = 4
id =ec2_B-id
Â
ec2_C:
counter = 3
id = ec2_B-id
counter = 5
id = ec2_A-id
Â
It seems the parallel actions is using the same session so vars gets mixed up between EC2 parallel steps.
parallel should execute each action in a separate session / thread to keep the vars encapsulated for the step that triggered it.