• Icon: Bug Bug
    • Resolution: Not A Defect
    • Icon: Blocker Blocker
    • groovy-plugin, pipeline
    • None
    • Jenkins on premise - ver. 2.175,
      Checked with Jenkins stabe 2.164.2 - same issue
      RH 7.6 server
      Latest version of all plugins [groovy, pipeline, declarative pipeline etc]

      When running declarative pipeline with two maps and using function something got mixed.

      example code:

       

      pipeline{
          agent { node 'builder_linux_1' }
          stages{
              stage('test'){
                  steps{
                      script{
                          first_map = [:]
                          first_map['JIRA-1'] = ['ArtifactId':'first_ART-1','ArtifactVersion':'1.0.3-1','ParentIssue':'JIRA-0']
                          first_map['JIRA-2'] = ['ArtifactId':'first_ART-2','ArtifactVersion':'1.0.3-1','ParentIssue':'JIRA-0']
                          second_map = [:]
                          second_map['JIRA-12'] = ['ArtifactId':'second_ARTIFACT-100','ArtifactVersion':'1.0.3-10','ParentIssue':'JIRA-0']
                          def ParallelSteps = [:]
                          ParallelSteps['first'] = {
                              test(first_map, 'FIRST')
                          }
                          ParallelSteps['second'] = {
                              test(second_map, 'SECOND')
                          }
                          parallel ParallelSteps
                      }
                  }       
              }
          }
      }
      void test(ARTIFACT_MAP, TECH){
          ARTIFACT_MAP.each { art ->
              if (TECH == 'SECOND'){
                  splited_artifact_name = art.value['ArtifactId'].tokenize('_')
                  splited_artifact_name.remove(splited_artifact_name[0])
                  TEMP_HOLDER_ARTIFACT_ID = splited_artifact_name.join('_')
              }
              else {
                  TEMP_HOLDER_ARTIFACT_ID = art.value['ArtifactId']
              }
              dir(TECH){
                  println "${TEMP_HOLDER_ARTIFACT_ID}, ${TECH}"
              }
          }
      }
      

      The output is:

      [Pipeline] stage
      [Pipeline] { (test)
      [Pipeline] script
      [Pipeline] {
      [Pipeline] parallel
      [Pipeline] { (Branch: first)
      [Pipeline] { (Branch: second)
      [Pipeline] dir
      Running in /home/devops/.jenkins/workspace/test_15/FIRST
      [Pipeline] {
      [Pipeline] dir
      Running in /home/devops/.jenkins/workspace/test_15/SECOND
      [Pipeline] {
      [Pipeline] echo
      ARTIFACT-100, FIRST
      [Pipeline] }
      [Pipeline] echo
      ARTIFACT-100, SECOND
      [Pipeline] }
      [Pipeline] // dir
      [Pipeline] // dir
      [Pipeline] }
      [Pipeline] dir
      Running in /home/devops/.jenkins/workspace/test_15/FIRST
      [Pipeline] {
      [Pipeline] echo
      first_ART-2, FIRST
      [Pipeline] }
      [Pipeline] // dir
      [Pipeline] }
      [Pipeline] // parallel
      [Pipeline] }
      [Pipeline] // script
      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] }
      [Pipeline] // node
      [Pipeline] End of Pipeline
      

      Now if in the mention pipeline i will remove the 'dir' function from the void function

      dir(TECH){ println "${TEMP_HOLDER_ARTIFACT_ID}, ${TECH}" }
      

      and just print:

      println "${TEMP_HOLDER_ARTIFACT_ID}, ${TECH}"
      

      everything looks fine....

      [Pipeline] { (Branch: first)
      [Pipeline] { (Branch: second)
      [Pipeline] echo
      first_ART-1, FIRST
      [Pipeline] echo
      ARTIFACT-100, SECOND
      [Pipeline] }
      [Pipeline] echo
      first_ART-2, FIRST
      

      found that it's work well if running the 'if statement' inside the dir func..

      void test(ARTIFACT_MAP, TECH){
          ARTIFACT_MAP.each { art ->
              dir(TECH){
                  if (TECH == 'SECOND'){
                      splited_artifact_name = art.value['ArtifactId'].tokenize('_')
                      splited_artifact_name.remove(splited_artifact_name[0])
                      TEMP_HOLDER_ARTIFACT_ID = splited_artifact_name.join('_')
                  }
                  else {
                      TEMP_HOLDER_ARTIFACT_ID = art.value['ArtifactId']
                  }
                  println "${TEMP_HOLDER_ARTIFACT_ID}, ${TECH}"
              }
          }
      }
      

       NOT WORKING IF TAKING THE PRINTLN OUTSIDE 'DIR()'

       

          [JENKINS-57336] Declarative Pipeline each loop in parallel step

          Kirill Kamaldinov created issue -
          Kirill Kamaldinov made changes -
          Description Original: When running declarative pipeline with two maps and using function something got mixed.

          example code:

           
          {code:java}
          pipeline{
              agent { node 'builder_linux_1' }
              stages{
                  stage('test'){
                      steps{
                          script{
                              first_map = [:]
                              first_map['JIRA-1'] = ['ArtifactId':'first_ART-1','ArtifactVersion':'1.0.3-1','ParentIssue':'JIRA-0']
                              first_map['JIRA-2'] = ['ArtifactId':'first_ART-2','ArtifactVersion':'1.0.3-1','ParentIssue':'JIRA-0']
                              second_map = [:]
                              second_map['JIRA-12'] = ['ArtifactId':'second_ARTIFACT-100','ArtifactVersion':'1.0.3-10','ParentIssue':'JIRA-0']
                              def ParallelSteps = [:]
                              ParallelSteps['first'] = {
                                  test(first_map, 'FIRST')
                              }
                              ParallelSteps['second'] = {
                                  test(second_map, 'SECOND')
                              }
                              parallel ParallelSteps
                          }
                      }
                  }
              }
          }
          void test(ARTIFACT_MAP, TECH){
              ARTIFACT_MAP.each { art ->
                  if (TECH == 'SECOND'){
                      splited_artifact_name = art.value['ArtifactId'].tokenize('_')
                      splited_artifact_name.remove(splited_artifact_name[0])
                      TEMP_HOLDER_ARTIFACT_ID = splited_artifact_name.join('_')
                  }
                  else {
                      TEMP_HOLDER_ARTIFACT_ID = art.value['ArtifactId']
                  }
                  dir(TECH){
                      println "${TEMP_HOLDER_ARTIFACT_ID}, ${TECH}"
                  }
              }
          }
          {code}
          The output is:
          {code:java}
          [Pipeline] stage
          [Pipeline] { (test)
          [Pipeline] script
          [Pipeline] {
          [Pipeline] parallel
          [Pipeline] { (Branch: first)
          [Pipeline] { (Branch: second)
          [Pipeline] dir
          Running in /home/devops/.jenkins/workspace/test_15/FIRST
          [Pipeline] {
          [Pipeline] dir
          Running in /home/devops/.jenkins/workspace/test_15/SECOND
          [Pipeline] {
          [Pipeline] echo
          ARTIFACT-100, FIRST
          [Pipeline] }
          [Pipeline] echo
          ARTIFACT-100, SECOND
          [Pipeline] }
          [Pipeline] // dir
          [Pipeline] // dir
          [Pipeline] }
          [Pipeline] dir
          Running in /home/devops/.jenkins/workspace/test_15/FIRST
          [Pipeline] {
          [Pipeline] echo
          first_ART-2, FIRST
          [Pipeline] }
          [Pipeline] // dir
          [Pipeline] }
          [Pipeline] // parallel
          [Pipeline] }
          [Pipeline] // script
          [Pipeline] }
          [Pipeline] // stage
          [Pipeline] }
          [Pipeline] // node
          [Pipeline] End of Pipeline
          {code}
          Now if in the mention pipeline i will remove the 'dir' function from the void function
          {code:java}
          dir(TECH){ println "${TEMP_HOLDER_ARTIFACT_ID}, ${TECH}" }
          {code}
          and just print:
          {code:java}
          println "${TEMP_HOLDER_ARTIFACT_ID}, ${TECH}"
          {code}
          everything looks fine....
          {code:java}
          [Pipeline] { (Branch: first)
          [Pipeline] { (Branch: second)
          [Pipeline] echo
          first_ART-1, FIRST
          [Pipeline] echo
          ARTIFACT-100, SECOND
          [Pipeline] }
          [Pipeline] echo
          first_ART-2, FIRST
          {code}
          New: When running declarative pipeline with two maps and using function something got mixed.

          example code:

           
          {code:java}
          pipeline{
              agent { node 'builder_linux_1' }
              stages{
                  stage('test'){
                      steps{
                          script{
                              first_map = [:]
                              first_map['JIRA-1'] = ['ArtifactId':'first_ART-1','ArtifactVersion':'1.0.3-1','ParentIssue':'JIRA-0']
                              first_map['JIRA-2'] = ['ArtifactId':'first_ART-2','ArtifactVersion':'1.0.3-1','ParentIssue':'JIRA-0']
                              second_map = [:]
                              second_map['JIRA-12'] = ['ArtifactId':'second_ARTIFACT-100','ArtifactVersion':'1.0.3-10','ParentIssue':'JIRA-0']
                              def ParallelSteps = [:]
                              ParallelSteps['first'] = {
                                  test(first_map, 'FIRST')
                              }
                              ParallelSteps['second'] = {
                                  test(second_map, 'SECOND')
                              }
                              parallel ParallelSteps
                          }
                      }
                  }
              }
          }
          void test(ARTIFACT_MAP, TECH){
              ARTIFACT_MAP.each { art ->
                  if (TECH == 'SECOND'){
                      splited_artifact_name = art.value['ArtifactId'].tokenize('_')
                      splited_artifact_name.remove(splited_artifact_name[0])
                      TEMP_HOLDER_ARTIFACT_ID = splited_artifact_name.join('_')
                  }
                  else {
                      TEMP_HOLDER_ARTIFACT_ID = art.value['ArtifactId']
                  }
                  dir(TECH){
                      println "${TEMP_HOLDER_ARTIFACT_ID}, ${TECH}"
                  }
              }
          }
          {code}
          The output is:
          {code:java}
          [Pipeline] stage
          [Pipeline] { (test)
          [Pipeline] script
          [Pipeline] {
          [Pipeline] parallel
          [Pipeline] { (Branch: first)
          [Pipeline] { (Branch: second)
          [Pipeline] dir
          Running in /home/devops/.jenkins/workspace/test_15/FIRST
          [Pipeline] {
          [Pipeline] dir
          Running in /home/devops/.jenkins/workspace/test_15/SECOND
          [Pipeline] {
          [Pipeline] echo
          ARTIFACT-100, FIRST
          [Pipeline] }
          [Pipeline] echo
          ARTIFACT-100, SECOND
          [Pipeline] }
          [Pipeline] // dir
          [Pipeline] // dir
          [Pipeline] }
          [Pipeline] dir
          Running in /home/devops/.jenkins/workspace/test_15/FIRST
          [Pipeline] {
          [Pipeline] echo
          first_ART-2, FIRST
          [Pipeline] }
          [Pipeline] // dir
          [Pipeline] }
          [Pipeline] // parallel
          [Pipeline] }
          [Pipeline] // script
          [Pipeline] }
          [Pipeline] // stage
          [Pipeline] }
          [Pipeline] // node
          [Pipeline] End of Pipeline
          {code}
          Now if in the mention pipeline i will remove the 'dir' function from the void function
          {code:java}
          dir(TECH){ println "${TEMP_HOLDER_ARTIFACT_ID}, ${TECH}" }
          {code}
          and just print:
          {code:java}
          println "${TEMP_HOLDER_ARTIFACT_ID}, ${TECH}"
          {code}
          everything looks fine....
          {code:java}
          [Pipeline] { (Branch: first)
          [Pipeline] { (Branch: second)
          [Pipeline] echo
          first_ART-1, FIRST
          [Pipeline] echo
          ARTIFACT-100, SECOND
          [Pipeline] }
          [Pipeline] echo
          first_ART-2, FIRST
          {code}
          found that it's work well if running the 'if statement' inside the dir func..
          {code:java}
          void test(ARTIFACT_MAP, TECH){
              ARTIFACT_MAP.each { art ->
                  dir(TECH){
                      if (TECH == 'SECOND'){
                          splited_artifact_name = art.value['ArtifactId'].tokenize('_')
                          splited_artifact_name.remove(splited_artifact_name[0])
                          TEMP_HOLDER_ARTIFACT_ID = splited_artifact_name.join('_')
                      }
                      else {
                          TEMP_HOLDER_ARTIFACT_ID = art.value['ArtifactId']
                      }
                      println "${TEMP_HOLDER_ARTIFACT_ID}, ${TECH}"
                  }
              }
          }
          {code}
           
          Kirill Kamaldinov made changes -
          Description Original: When running declarative pipeline with two maps and using function something got mixed.

          example code:

           
          {code:java}
          pipeline{
              agent { node 'builder_linux_1' }
              stages{
                  stage('test'){
                      steps{
                          script{
                              first_map = [:]
                              first_map['JIRA-1'] = ['ArtifactId':'first_ART-1','ArtifactVersion':'1.0.3-1','ParentIssue':'JIRA-0']
                              first_map['JIRA-2'] = ['ArtifactId':'first_ART-2','ArtifactVersion':'1.0.3-1','ParentIssue':'JIRA-0']
                              second_map = [:]
                              second_map['JIRA-12'] = ['ArtifactId':'second_ARTIFACT-100','ArtifactVersion':'1.0.3-10','ParentIssue':'JIRA-0']
                              def ParallelSteps = [:]
                              ParallelSteps['first'] = {
                                  test(first_map, 'FIRST')
                              }
                              ParallelSteps['second'] = {
                                  test(second_map, 'SECOND')
                              }
                              parallel ParallelSteps
                          }
                      }
                  }
              }
          }
          void test(ARTIFACT_MAP, TECH){
              ARTIFACT_MAP.each { art ->
                  if (TECH == 'SECOND'){
                      splited_artifact_name = art.value['ArtifactId'].tokenize('_')
                      splited_artifact_name.remove(splited_artifact_name[0])
                      TEMP_HOLDER_ARTIFACT_ID = splited_artifact_name.join('_')
                  }
                  else {
                      TEMP_HOLDER_ARTIFACT_ID = art.value['ArtifactId']
                  }
                  dir(TECH){
                      println "${TEMP_HOLDER_ARTIFACT_ID}, ${TECH}"
                  }
              }
          }
          {code}
          The output is:
          {code:java}
          [Pipeline] stage
          [Pipeline] { (test)
          [Pipeline] script
          [Pipeline] {
          [Pipeline] parallel
          [Pipeline] { (Branch: first)
          [Pipeline] { (Branch: second)
          [Pipeline] dir
          Running in /home/devops/.jenkins/workspace/test_15/FIRST
          [Pipeline] {
          [Pipeline] dir
          Running in /home/devops/.jenkins/workspace/test_15/SECOND
          [Pipeline] {
          [Pipeline] echo
          ARTIFACT-100, FIRST
          [Pipeline] }
          [Pipeline] echo
          ARTIFACT-100, SECOND
          [Pipeline] }
          [Pipeline] // dir
          [Pipeline] // dir
          [Pipeline] }
          [Pipeline] dir
          Running in /home/devops/.jenkins/workspace/test_15/FIRST
          [Pipeline] {
          [Pipeline] echo
          first_ART-2, FIRST
          [Pipeline] }
          [Pipeline] // dir
          [Pipeline] }
          [Pipeline] // parallel
          [Pipeline] }
          [Pipeline] // script
          [Pipeline] }
          [Pipeline] // stage
          [Pipeline] }
          [Pipeline] // node
          [Pipeline] End of Pipeline
          {code}
          Now if in the mention pipeline i will remove the 'dir' function from the void function
          {code:java}
          dir(TECH){ println "${TEMP_HOLDER_ARTIFACT_ID}, ${TECH}" }
          {code}
          and just print:
          {code:java}
          println "${TEMP_HOLDER_ARTIFACT_ID}, ${TECH}"
          {code}
          everything looks fine....
          {code:java}
          [Pipeline] { (Branch: first)
          [Pipeline] { (Branch: second)
          [Pipeline] echo
          first_ART-1, FIRST
          [Pipeline] echo
          ARTIFACT-100, SECOND
          [Pipeline] }
          [Pipeline] echo
          first_ART-2, FIRST
          {code}
          found that it's work well if running the 'if statement' inside the dir func..
          {code:java}
          void test(ARTIFACT_MAP, TECH){
              ARTIFACT_MAP.each { art ->
                  dir(TECH){
                      if (TECH == 'SECOND'){
                          splited_artifact_name = art.value['ArtifactId'].tokenize('_')
                          splited_artifact_name.remove(splited_artifact_name[0])
                          TEMP_HOLDER_ARTIFACT_ID = splited_artifact_name.join('_')
                      }
                      else {
                          TEMP_HOLDER_ARTIFACT_ID = art.value['ArtifactId']
                      }
                      println "${TEMP_HOLDER_ARTIFACT_ID}, ${TECH}"
                  }
              }
          }
          {code}
           
          New: When running declarative pipeline with two maps and using function something got mixed.

          example code:

           
          {code:java}
          pipeline{
              agent { node 'builder_linux_1' }
              stages{
                  stage('test'){
                      steps{
                          script{
                              first_map = [:]
                              first_map['JIRA-1'] = ['ArtifactId':'first_ART-1','ArtifactVersion':'1.0.3-1','ParentIssue':'JIRA-0']
                              first_map['JIRA-2'] = ['ArtifactId':'first_ART-2','ArtifactVersion':'1.0.3-1','ParentIssue':'JIRA-0']
                              second_map = [:]
                              second_map['JIRA-12'] = ['ArtifactId':'second_ARTIFACT-100','ArtifactVersion':'1.0.3-10','ParentIssue':'JIRA-0']
                              def ParallelSteps = [:]
                              ParallelSteps['first'] = {
                                  test(first_map, 'FIRST')
                              }
                              ParallelSteps['second'] = {
                                  test(second_map, 'SECOND')
                              }
                              parallel ParallelSteps
                          }
                      }
                  }
              }
          }
          void test(ARTIFACT_MAP, TECH){
              ARTIFACT_MAP.each { art ->
                  if (TECH == 'SECOND'){
                      splited_artifact_name = art.value['ArtifactId'].tokenize('_')
                      splited_artifact_name.remove(splited_artifact_name[0])
                      TEMP_HOLDER_ARTIFACT_ID = splited_artifact_name.join('_')
                  }
                  else {
                      TEMP_HOLDER_ARTIFACT_ID = art.value['ArtifactId']
                  }
                  dir(TECH){
                      println "${TEMP_HOLDER_ARTIFACT_ID}, ${TECH}"
                  }
              }
          }
          {code}
          The output is:
          {code:java}
          [Pipeline] stage
          [Pipeline] { (test)
          [Pipeline] script
          [Pipeline] {
          [Pipeline] parallel
          [Pipeline] { (Branch: first)
          [Pipeline] { (Branch: second)
          [Pipeline] dir
          Running in /home/devops/.jenkins/workspace/test_15/FIRST
          [Pipeline] {
          [Pipeline] dir
          Running in /home/devops/.jenkins/workspace/test_15/SECOND
          [Pipeline] {
          [Pipeline] echo
          ARTIFACT-100, FIRST
          [Pipeline] }
          [Pipeline] echo
          ARTIFACT-100, SECOND
          [Pipeline] }
          [Pipeline] // dir
          [Pipeline] // dir
          [Pipeline] }
          [Pipeline] dir
          Running in /home/devops/.jenkins/workspace/test_15/FIRST
          [Pipeline] {
          [Pipeline] echo
          first_ART-2, FIRST
          [Pipeline] }
          [Pipeline] // dir
          [Pipeline] }
          [Pipeline] // parallel
          [Pipeline] }
          [Pipeline] // script
          [Pipeline] }
          [Pipeline] // stage
          [Pipeline] }
          [Pipeline] // node
          [Pipeline] End of Pipeline
          {code}
          Now if in the mention pipeline i will remove the 'dir' function from the void function
          {code:java}
          dir(TECH){ println "${TEMP_HOLDER_ARTIFACT_ID}, ${TECH}" }
          {code}
          and just print:
          {code:java}
          println "${TEMP_HOLDER_ARTIFACT_ID}, ${TECH}"
          {code}
          everything looks fine....
          {code:java}
          [Pipeline] { (Branch: first)
          [Pipeline] { (Branch: second)
          [Pipeline] echo
          first_ART-1, FIRST
          [Pipeline] echo
          ARTIFACT-100, SECOND
          [Pipeline] }
          [Pipeline] echo
          first_ART-2, FIRST
          {code}
          found that it's work well if running the 'if statement' inside the dir func..
          {code:java}
          void test(ARTIFACT_MAP, TECH){
              ARTIFACT_MAP.each { art ->
                  dir(TECH){
                      if (TECH == 'SECOND'){
                          splited_artifact_name = art.value['ArtifactId'].tokenize('_')
                          splited_artifact_name.remove(splited_artifact_name[0])
                          TEMP_HOLDER_ARTIFACT_ID = splited_artifact_name.join('_')
                      }
                      else {
                          TEMP_HOLDER_ARTIFACT_ID = art.value['ArtifactId']
                      }
                      println "${TEMP_HOLDER_ARTIFACT_ID}, ${TECH}"
                  }
              }
          }
          {code}
           

          another founding :

          If after the last working statement (when running the if statement on the same dir) running in another dir - the result is mixed again

          e.g:

           
          {code:java}
          void test(ARTIFACT_MAP, TECH){
              ARTIFACT_MAP.each { art ->
                  dir(TECH){
                      if (TECH == 'SECOND'){
                          splited_artifact_name = art.value['ArtifactId'].tokenize('_')
                          splited_artifact_name.remove(splited_artifact_name[0])
                          TEMP_HOLDER_ARTIFACT_ID = splited_artifact_name.join('_')
                      }
                      else {
                          TEMP_HOLDER_ARTIFACT_ID = art.value['ArtifactId']
                      }
                      println "${TEMP_HOLDER_ARTIFACT_ID}, ${TECH}" //prints the right values
                  }
                  dir('test'){
                      println "${TEMP_HOLDER_ARTIFACT_ID}, ${TECH}" // won't work as it should
                  }
              }
          }
          {code}
           
          Kirill Kamaldinov made changes -
          Priority Original: Critical [ 2 ] New: Blocker [ 1 ]
          Kirill Kamaldinov made changes -
          Description Original: When running declarative pipeline with two maps and using function something got mixed.

          example code:

           
          {code:java}
          pipeline{
              agent { node 'builder_linux_1' }
              stages{
                  stage('test'){
                      steps{
                          script{
                              first_map = [:]
                              first_map['JIRA-1'] = ['ArtifactId':'first_ART-1','ArtifactVersion':'1.0.3-1','ParentIssue':'JIRA-0']
                              first_map['JIRA-2'] = ['ArtifactId':'first_ART-2','ArtifactVersion':'1.0.3-1','ParentIssue':'JIRA-0']
                              second_map = [:]
                              second_map['JIRA-12'] = ['ArtifactId':'second_ARTIFACT-100','ArtifactVersion':'1.0.3-10','ParentIssue':'JIRA-0']
                              def ParallelSteps = [:]
                              ParallelSteps['first'] = {
                                  test(first_map, 'FIRST')
                              }
                              ParallelSteps['second'] = {
                                  test(second_map, 'SECOND')
                              }
                              parallel ParallelSteps
                          }
                      }
                  }
              }
          }
          void test(ARTIFACT_MAP, TECH){
              ARTIFACT_MAP.each { art ->
                  if (TECH == 'SECOND'){
                      splited_artifact_name = art.value['ArtifactId'].tokenize('_')
                      splited_artifact_name.remove(splited_artifact_name[0])
                      TEMP_HOLDER_ARTIFACT_ID = splited_artifact_name.join('_')
                  }
                  else {
                      TEMP_HOLDER_ARTIFACT_ID = art.value['ArtifactId']
                  }
                  dir(TECH){
                      println "${TEMP_HOLDER_ARTIFACT_ID}, ${TECH}"
                  }
              }
          }
          {code}
          The output is:
          {code:java}
          [Pipeline] stage
          [Pipeline] { (test)
          [Pipeline] script
          [Pipeline] {
          [Pipeline] parallel
          [Pipeline] { (Branch: first)
          [Pipeline] { (Branch: second)
          [Pipeline] dir
          Running in /home/devops/.jenkins/workspace/test_15/FIRST
          [Pipeline] {
          [Pipeline] dir
          Running in /home/devops/.jenkins/workspace/test_15/SECOND
          [Pipeline] {
          [Pipeline] echo
          ARTIFACT-100, FIRST
          [Pipeline] }
          [Pipeline] echo
          ARTIFACT-100, SECOND
          [Pipeline] }
          [Pipeline] // dir
          [Pipeline] // dir
          [Pipeline] }
          [Pipeline] dir
          Running in /home/devops/.jenkins/workspace/test_15/FIRST
          [Pipeline] {
          [Pipeline] echo
          first_ART-2, FIRST
          [Pipeline] }
          [Pipeline] // dir
          [Pipeline] }
          [Pipeline] // parallel
          [Pipeline] }
          [Pipeline] // script
          [Pipeline] }
          [Pipeline] // stage
          [Pipeline] }
          [Pipeline] // node
          [Pipeline] End of Pipeline
          {code}
          Now if in the mention pipeline i will remove the 'dir' function from the void function
          {code:java}
          dir(TECH){ println "${TEMP_HOLDER_ARTIFACT_ID}, ${TECH}" }
          {code}
          and just print:
          {code:java}
          println "${TEMP_HOLDER_ARTIFACT_ID}, ${TECH}"
          {code}
          everything looks fine....
          {code:java}
          [Pipeline] { (Branch: first)
          [Pipeline] { (Branch: second)
          [Pipeline] echo
          first_ART-1, FIRST
          [Pipeline] echo
          ARTIFACT-100, SECOND
          [Pipeline] }
          [Pipeline] echo
          first_ART-2, FIRST
          {code}
          found that it's work well if running the 'if statement' inside the dir func..
          {code:java}
          void test(ARTIFACT_MAP, TECH){
              ARTIFACT_MAP.each { art ->
                  dir(TECH){
                      if (TECH == 'SECOND'){
                          splited_artifact_name = art.value['ArtifactId'].tokenize('_')
                          splited_artifact_name.remove(splited_artifact_name[0])
                          TEMP_HOLDER_ARTIFACT_ID = splited_artifact_name.join('_')
                      }
                      else {
                          TEMP_HOLDER_ARTIFACT_ID = art.value['ArtifactId']
                      }
                      println "${TEMP_HOLDER_ARTIFACT_ID}, ${TECH}"
                  }
              }
          }
          {code}
           

          another founding :

          If after the last working statement (when running the if statement on the same dir) running in another dir - the result is mixed again

          e.g:

           
          {code:java}
          void test(ARTIFACT_MAP, TECH){
              ARTIFACT_MAP.each { art ->
                  dir(TECH){
                      if (TECH == 'SECOND'){
                          splited_artifact_name = art.value['ArtifactId'].tokenize('_')
                          splited_artifact_name.remove(splited_artifact_name[0])
                          TEMP_HOLDER_ARTIFACT_ID = splited_artifact_name.join('_')
                      }
                      else {
                          TEMP_HOLDER_ARTIFACT_ID = art.value['ArtifactId']
                      }
                      println "${TEMP_HOLDER_ARTIFACT_ID}, ${TECH}" //prints the right values
                  }
                  dir('test'){
                      println "${TEMP_HOLDER_ARTIFACT_ID}, ${TECH}" // won't work as it should
                  }
              }
          }
          {code}
           
          New: When running declarative pipeline with two maps and using function something got mixed.

          example code:

           
          {code:java}
          pipeline{
              agent { node 'builder_linux_1' }
              stages{
                  stage('test'){
                      steps{
                          script{
                              first_map = [:]
                              first_map['JIRA-1'] = ['ArtifactId':'first_ART-1','ArtifactVersion':'1.0.3-1','ParentIssue':'JIRA-0']
                              first_map['JIRA-2'] = ['ArtifactId':'first_ART-2','ArtifactVersion':'1.0.3-1','ParentIssue':'JIRA-0']
                              second_map = [:]
                              second_map['JIRA-12'] = ['ArtifactId':'second_ARTIFACT-100','ArtifactVersion':'1.0.3-10','ParentIssue':'JIRA-0']
                              def ParallelSteps = [:]
                              ParallelSteps['first'] = {
                                  test(first_map, 'FIRST')
                              }
                              ParallelSteps['second'] = {
                                  test(second_map, 'SECOND')
                              }
                              parallel ParallelSteps
                          }
                      }
                  }
              }
          }
          void test(ARTIFACT_MAP, TECH){
              ARTIFACT_MAP.each { art ->
                  if (TECH == 'SECOND'){
                      splited_artifact_name = art.value['ArtifactId'].tokenize('_')
                      splited_artifact_name.remove(splited_artifact_name[0])
                      TEMP_HOLDER_ARTIFACT_ID = splited_artifact_name.join('_')
                  }
                  else {
                      TEMP_HOLDER_ARTIFACT_ID = art.value['ArtifactId']
                  }
                  dir(TECH){
                      println "${TEMP_HOLDER_ARTIFACT_ID}, ${TECH}"
                  }
              }
          }
          {code}
          The output is:
          {code:java}
          [Pipeline] stage
          [Pipeline] { (test)
          [Pipeline] script
          [Pipeline] {
          [Pipeline] parallel
          [Pipeline] { (Branch: first)
          [Pipeline] { (Branch: second)
          [Pipeline] dir
          Running in /home/devops/.jenkins/workspace/test_15/FIRST
          [Pipeline] {
          [Pipeline] dir
          Running in /home/devops/.jenkins/workspace/test_15/SECOND
          [Pipeline] {
          [Pipeline] echo
          ARTIFACT-100, FIRST
          [Pipeline] }
          [Pipeline] echo
          ARTIFACT-100, SECOND
          [Pipeline] }
          [Pipeline] // dir
          [Pipeline] // dir
          [Pipeline] }
          [Pipeline] dir
          Running in /home/devops/.jenkins/workspace/test_15/FIRST
          [Pipeline] {
          [Pipeline] echo
          first_ART-2, FIRST
          [Pipeline] }
          [Pipeline] // dir
          [Pipeline] }
          [Pipeline] // parallel
          [Pipeline] }
          [Pipeline] // script
          [Pipeline] }
          [Pipeline] // stage
          [Pipeline] }
          [Pipeline] // node
          [Pipeline] End of Pipeline
          {code}
          Now if in the mention pipeline i will remove the 'dir' function from the void function
          {code:java}
          dir(TECH){ println "${TEMP_HOLDER_ARTIFACT_ID}, ${TECH}" }
          {code}
          and just print:
          {code:java}
          println "${TEMP_HOLDER_ARTIFACT_ID}, ${TECH}"
          {code}
          everything looks fine....
          {code:java}
          [Pipeline] { (Branch: first)
          [Pipeline] { (Branch: second)
          [Pipeline] echo
          first_ART-1, FIRST
          [Pipeline] echo
          ARTIFACT-100, SECOND
          [Pipeline] }
          [Pipeline] echo
          first_ART-2, FIRST
          {code}
          found that it's work well if running the 'if statement' inside the dir func..
          {code:java}
          void test(ARTIFACT_MAP, TECH){
              ARTIFACT_MAP.each { art ->
                  dir(TECH){
                      if (TECH == 'SECOND'){
                          splited_artifact_name = art.value['ArtifactId'].tokenize('_')
                          splited_artifact_name.remove(splited_artifact_name[0])
                          TEMP_HOLDER_ARTIFACT_ID = splited_artifact_name.join('_')
                      }
                      else {
                          TEMP_HOLDER_ARTIFACT_ID = art.value['ArtifactId']
                      }
                      println "${TEMP_HOLDER_ARTIFACT_ID}, ${TECH}"
                  }
              }
          }
          {code}
           NOT WORKING IF TAKING THE PRINTLN OUTSIDE 'DIR()'

           
          Kirill Kamaldinov made changes -
          Environment Original: Jenkins on premise - ver. 2.175
          RH 7.6 server
          Latest version of all plugins [groovy, pipeline, declarative pipeline etc]
          New: Jenkins on premise - ver. 2.175,
          Checked with Jenkins stabe 2.164.2 - same issue
          RH 7.6 server
          Latest version of all plugins [groovy, pipeline, declarative pipeline etc]

          found this issue a long time later  all needed is adding 'def' when creating vars

          Kirill Kamaldinov added a comment - found this issue a long time later  all needed is adding 'def' when creating vars
          Kirill Kamaldinov made changes -
          Resolution New: Not A Defect [ 7 ]
          Status Original: Open [ 1 ] New: Fixed but Unreleased [ 10203 ]

            vjuranek vjuranek
            apresfiux Kirill Kamaldinov
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: