Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-75166

Parallel [:] using same session - unsafe to execute same function in parallel

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • pipeline
    • None
    • 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.

            Unassigned Unassigned
            mapel88 Maayan
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: