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

P4 Plugin: "cleanup true" missing cleaning other P4Clients during Parallel Stages

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • p4-plugin
    • P4 Plugin: 1.9.4
      Jenkins: 2.138.3

      I have the following pipelines which using parallel stage to checkout source codes from Perforce for Sonar and UT:

      #!/usr/bin/env groovy
      pipeline {
          agent any
          options {
              timestamps()
              skipDefaultCheckout()
          }
          stages {
              stage('P4 Parallel Checkout Test') {
                  failFast true
                  parallel {
                      stage('UT') {
                          steps {
                              script {
                                  def p4Client = "jenkins-${JOB_NAME}-UT"
                                  checkout perforce(credential: "P4",
                                           populate: forceClean(have: true, parallel: [enable: false, minbytes: '1024', minfiles: '1', threads: '4'], pin: '', quiet: true), 
                                           workspace: streamSpec(charset: 'none', format: "${p4Client}", pinHost: false, streamName: "//Stream/devStream"))             
                                
                              }
                          }
                          post {
                              always {
                                  script {
                                      echo "delete P4CLIENT UT"
                                      cleanup true
                                  }
                              }
                          }
                      }
                      stage('Sonar') {
                          steps {
                              script {
                                  def p4Client = "jenkins-${JOB_NAME}-Sonar"
                                  checkout perforce(credential: "P4",
                                           populate: forceClean(have: true, parallel: [enable: false, minbytes: '1024', minfiles: '1', threads: '4'], pin: '', quiet: true), 
                                           workspace: streamSpec(charset: 'none', format: "${p4Client}", pinHost: false, streamName: "//Stream/devStream"))             
                              }
                          }
                          post {
                              always {
                                  script {
                                      echo "delete P4CLIENT Sonar"
                                      cleanup true
                                  }
                              }
                          }
                      }
                  }  // end parallel
              }
          } // end stges
      }
      

      I expected both P4CLIENT will be deleted after the job execution, but when I see the log, ONLY one is deleted. The log showed that one "cleanup" step didn't get the P4CLIENT correctly. See attachments for details.

          [JENKINS-54638] P4 Plugin: "cleanup true" missing cleaning other P4Clients during Parallel Stages

          Xuezhong Yan created issue -
          Xuezhong Yan made changes -
          Description New: Hi,

          Xuezhong Yan made changes -
          Description Original: Hi,

          New: I have the following pipelines which using parallel stage to checkout source codes from Perforce:

          {code:groovy}
          #!/usr/bin/env groovy
          pipeline {
              agent any
              stages {
                  stage('P4 Parallel Checkout Test') {
                      failFast true
                      parallel {
                          stage('UT') {
                              steps {
                                  script {
                                      def p4Client = "jenkins-${JOB_NAME}-UT"
                                      checkout perforce(credential: "P4",
                                               populate: forceClean(have: true, parallel: [enable: false, minbytes: '1024', minfiles: '1', threads: '4'], pin: '', quiet: true),
                                               workspace: streamSpec(charset: 'none', format: "${p4Client}", pinHost: false, streamName: "//Stream/devStream"))
                                    
                                  }
                              }
                              post {
                                  always {
                                      script {
                                          echo "delete P4CLIENT UT"
                                          cleanup true
                                      }
                                  }
                              }
                          }
                          stage('Sonar') {
                              steps {
                                  script {
                                      def p4Client = "jenkins-${JOB_NAME}-Sonar"
                                      checkout perforce(credential: "P4",
                                               populate: forceClean(have: true, parallel: [enable: false, minbytes: '1024', minfiles: '1', threads: '4'], pin: '', quiet: true),
                                               workspace: streamSpec(charset: 'none', format: "${p4Client}", pinHost: false, streamName: "//Stream/devStream"))
                                  }
                              }
                              post {
                                  always {
                                      script {
                                          echo "delete P4CLIENT Sonar"
                                          cleanup true
                                      }
                                  }
                              }
                          }
                      } // end parallel
                  }
              } // end stges
          }
          {code}
          Xuezhong Yan made changes -
          Description Original: I have the following pipelines which using parallel stage to checkout source codes from Perforce:

          {code:groovy}
          #!/usr/bin/env groovy
          pipeline {
              agent any
              stages {
                  stage('P4 Parallel Checkout Test') {
                      failFast true
                      parallel {
                          stage('UT') {
                              steps {
                                  script {
                                      def p4Client = "jenkins-${JOB_NAME}-UT"
                                      checkout perforce(credential: "P4",
                                               populate: forceClean(have: true, parallel: [enable: false, minbytes: '1024', minfiles: '1', threads: '4'], pin: '', quiet: true),
                                               workspace: streamSpec(charset: 'none', format: "${p4Client}", pinHost: false, streamName: "//Stream/devStream"))
                                    
                                  }
                              }
                              post {
                                  always {
                                      script {
                                          echo "delete P4CLIENT UT"
                                          cleanup true
                                      }
                                  }
                              }
                          }
                          stage('Sonar') {
                              steps {
                                  script {
                                      def p4Client = "jenkins-${JOB_NAME}-Sonar"
                                      checkout perforce(credential: "P4",
                                               populate: forceClean(have: true, parallel: [enable: false, minbytes: '1024', minfiles: '1', threads: '4'], pin: '', quiet: true),
                                               workspace: streamSpec(charset: 'none', format: "${p4Client}", pinHost: false, streamName: "//Stream/devStream"))
                                  }
                              }
                              post {
                                  always {
                                      script {
                                          echo "delete P4CLIENT Sonar"
                                          cleanup true
                                      }
                                  }
                              }
                          }
                      } // end parallel
                  }
              } // end stges
          }
          {code}
          New: I have the following pipelines which using parallel stage to checkout source codes from Perforce for Sonar and UT:
          {code:groovy}
          #!/usr/bin/env groovy
          pipeline {
              agent any
              stages {
                  stage('P4 Parallel Checkout Test') {
                      failFast true
                      parallel {
                          stage('UT') {
                              steps {
                                  script {
                                      def p4Client = "jenkins-${JOB_NAME}-UT"
                                      checkout perforce(credential: "P4",
                                               populate: forceClean(have: true, parallel: [enable: false, minbytes: '1024', minfiles: '1', threads: '4'], pin: '', quiet: true),
                                               workspace: streamSpec(charset: 'none', format: "${p4Client}", pinHost: false, streamName: "//Stream/devStream"))
                                    
                                  }
                              }
                              post {
                                  always {
                                      script {
                                          echo "delete P4CLIENT UT"
                                          cleanup true
                                      }
                                  }
                              }
                          }
                          stage('Sonar') {
                              steps {
                                  script {
                                      def p4Client = "jenkins-${JOB_NAME}-Sonar"
                                      checkout perforce(credential: "P4",
                                               populate: forceClean(have: true, parallel: [enable: false, minbytes: '1024', minfiles: '1', threads: '4'], pin: '', quiet: true),
                                               workspace: streamSpec(charset: 'none', format: "${p4Client}", pinHost: false, streamName: "//Stream/devStream"))
                                  }
                              }
                              post {
                                  always {
                                      script {
                                          echo "delete P4CLIENT Sonar"
                                          cleanup true
                                      }
                                  }
                              }
                          }
                      } // end parallel
                  }
              } // end stges
          }
          {code}
          Xuezhong Yan made changes -
          Description Original: I have the following pipelines which using parallel stage to checkout source codes from Perforce for Sonar and UT:
          {code:groovy}
          #!/usr/bin/env groovy
          pipeline {
              agent any
              stages {
                  stage('P4 Parallel Checkout Test') {
                      failFast true
                      parallel {
                          stage('UT') {
                              steps {
                                  script {
                                      def p4Client = "jenkins-${JOB_NAME}-UT"
                                      checkout perforce(credential: "P4",
                                               populate: forceClean(have: true, parallel: [enable: false, minbytes: '1024', minfiles: '1', threads: '4'], pin: '', quiet: true),
                                               workspace: streamSpec(charset: 'none', format: "${p4Client}", pinHost: false, streamName: "//Stream/devStream"))
                                    
                                  }
                              }
                              post {
                                  always {
                                      script {
                                          echo "delete P4CLIENT UT"
                                          cleanup true
                                      }
                                  }
                              }
                          }
                          stage('Sonar') {
                              steps {
                                  script {
                                      def p4Client = "jenkins-${JOB_NAME}-Sonar"
                                      checkout perforce(credential: "P4",
                                               populate: forceClean(have: true, parallel: [enable: false, minbytes: '1024', minfiles: '1', threads: '4'], pin: '', quiet: true),
                                               workspace: streamSpec(charset: 'none', format: "${p4Client}", pinHost: false, streamName: "//Stream/devStream"))
                                  }
                              }
                              post {
                                  always {
                                      script {
                                          echo "delete P4CLIENT Sonar"
                                          cleanup true
                                      }
                                  }
                              }
                          }
                      } // end parallel
                  }
              } // end stges
          }
          {code}
          New: I have the following pipelines which using parallel stage to checkout source codes from Perforce for Sonar and UT:
          {code:groovy}
          #!/usr/bin/env groovy
          pipeline {
              agent any
              stages {
                  stage('P4 Parallel Checkout Test') {
                      failFast true
                      parallel {
                          stage('UT') {
                              steps {
                                  script {
                                      def p4Client = "jenkins-${JOB_NAME}-UT"
                                      checkout perforce(credential: "P4",
                                               populate: forceClean(have: true, parallel: [enable: false, minbytes: '1024', minfiles: '1', threads: '4'], pin: '', quiet: true),
                                               workspace: streamSpec(charset: 'none', format: "${p4Client}", pinHost: false, streamName: "//Stream/devStream"))
                                    
                                  }
                              }
                              post {
                                  always {
                                      script {
                                          echo "delete P4CLIENT UT"
                                          cleanup true
                                      }
                                  }
                              }
                          }
                          stage('Sonar') {
                              steps {
                                  script {
                                      def p4Client = "jenkins-${JOB_NAME}-Sonar"
                                      checkout perforce(credential: "P4",
                                               populate: forceClean(have: true, parallel: [enable: false, minbytes: '1024', minfiles: '1', threads: '4'], pin: '', quiet: true),
                                               workspace: streamSpec(charset: 'none', format: "${p4Client}", pinHost: false, streamName: "//Stream/devStream"))
                                  }
                              }
                              post {
                                  always {
                                      script {
                                          echo "delete P4CLIENT Sonar"
                                          cleanup true
                                      }
                                  }
                              }
                          }
                      } // end parallel
                  }
              } // end stges
          }
          {code}

          I expected both P4CLIENT will be deleted after the job execution, but when I see the log, *ONLY* one is deleted, see attached files.
          Xuezhong Yan made changes -
          Attachment New: screenshot-1.png [ 45163 ]
          Xuezhong Yan made changes -
          Attachment New: screenshot-2.png [ 45164 ]
          Xuezhong Yan made changes -
          Description Original: I have the following pipelines which using parallel stage to checkout source codes from Perforce for Sonar and UT:
          {code:groovy}
          #!/usr/bin/env groovy
          pipeline {
              agent any
              stages {
                  stage('P4 Parallel Checkout Test') {
                      failFast true
                      parallel {
                          stage('UT') {
                              steps {
                                  script {
                                      def p4Client = "jenkins-${JOB_NAME}-UT"
                                      checkout perforce(credential: "P4",
                                               populate: forceClean(have: true, parallel: [enable: false, minbytes: '1024', minfiles: '1', threads: '4'], pin: '', quiet: true),
                                               workspace: streamSpec(charset: 'none', format: "${p4Client}", pinHost: false, streamName: "//Stream/devStream"))
                                    
                                  }
                              }
                              post {
                                  always {
                                      script {
                                          echo "delete P4CLIENT UT"
                                          cleanup true
                                      }
                                  }
                              }
                          }
                          stage('Sonar') {
                              steps {
                                  script {
                                      def p4Client = "jenkins-${JOB_NAME}-Sonar"
                                      checkout perforce(credential: "P4",
                                               populate: forceClean(have: true, parallel: [enable: false, minbytes: '1024', minfiles: '1', threads: '4'], pin: '', quiet: true),
                                               workspace: streamSpec(charset: 'none', format: "${p4Client}", pinHost: false, streamName: "//Stream/devStream"))
                                  }
                              }
                              post {
                                  always {
                                      script {
                                          echo "delete P4CLIENT Sonar"
                                          cleanup true
                                      }
                                  }
                              }
                          }
                      } // end parallel
                  }
              } // end stges
          }
          {code}

          I expected both P4CLIENT will be deleted after the job execution, but when I see the log, *ONLY* one is deleted, see attached files.
          New: I have the following pipelines which using parallel stage to checkout source codes from Perforce for Sonar and UT:
          {code:groovy}
          #!/usr/bin/env groovy
          pipeline {
              agent any
              stages {
                  stage('P4 Parallel Checkout Test') {
                      failFast true
                      parallel {
                          stage('UT') {
                              steps {
                                  script {
                                      def p4Client = "jenkins-${JOB_NAME}-UT"
                                      checkout perforce(credential: "P4",
                                               populate: forceClean(have: true, parallel: [enable: false, minbytes: '1024', minfiles: '1', threads: '4'], pin: '', quiet: true),
                                               workspace: streamSpec(charset: 'none', format: "${p4Client}", pinHost: false, streamName: "//Stream/devStream"))
                                    
                                  }
                              }
                              post {
                                  always {
                                      script {
                                          echo "delete P4CLIENT UT"
                                          cleanup true
                                      }
                                  }
                              }
                          }
                          stage('Sonar') {
                              steps {
                                  script {
                                      def p4Client = "jenkins-${JOB_NAME}-Sonar"
                                      checkout perforce(credential: "P4",
                                               populate: forceClean(have: true, parallel: [enable: false, minbytes: '1024', minfiles: '1', threads: '4'], pin: '', quiet: true),
                                               workspace: streamSpec(charset: 'none', format: "${p4Client}", pinHost: false, streamName: "//Stream/devStream"))
                                  }
                              }
                              post {
                                  always {
                                      script {
                                          echo "delete P4CLIENT Sonar"
                                          cleanup true
                                      }
                                  }
                              }
                          }
                      } // end parallel
                  }
              } // end stges
          }
          {code}

          I expected both P4CLIENT will be deleted after the job execution, but when I see the log, *ONLY* one is deleted. The log showed that one "cleanup" step didn't get the P4CLIENT correctly. See attachments for details.

          BTW: I checked the P4 code, would the following code be the possible cause?
          p4-plugin\src\main\java\org\jenkinsci\plugins\p4\tagging\TagAction.java
          {code:java}
          /**
          * Find the last action; use this for environment variable as the last action has the latest values.
          *
          * @param run The current build
          * @return Action
          */
          public static TagAction getLastAction(Run<?, ?> run) {
          List<TagAction> actions = lastActions(run);
          if (actions == null) {
          return null;
          }

          // #Review 21165
          TagAction tagAction = run.getAction(TagAction.class);
          for (TagAction t : run.getActions(TagAction.class)) {
          tagAction = (t != null) ? t : tagAction;
          }
          return tagAction;
          }
          {code}


           !screenshot-1.png|thumbnail! !screenshot-2.png|thumbnail!
          Xuezhong Yan made changes -
          Assignee New: Paul Allen [ p4paul ]
          Xuezhong Yan made changes -
          Description Original: I have the following pipelines which using parallel stage to checkout source codes from Perforce for Sonar and UT:
          {code:groovy}
          #!/usr/bin/env groovy
          pipeline {
              agent any
              stages {
                  stage('P4 Parallel Checkout Test') {
                      failFast true
                      parallel {
                          stage('UT') {
                              steps {
                                  script {
                                      def p4Client = "jenkins-${JOB_NAME}-UT"
                                      checkout perforce(credential: "P4",
                                               populate: forceClean(have: true, parallel: [enable: false, minbytes: '1024', minfiles: '1', threads: '4'], pin: '', quiet: true),
                                               workspace: streamSpec(charset: 'none', format: "${p4Client}", pinHost: false, streamName: "//Stream/devStream"))
                                    
                                  }
                              }
                              post {
                                  always {
                                      script {
                                          echo "delete P4CLIENT UT"
                                          cleanup true
                                      }
                                  }
                              }
                          }
                          stage('Sonar') {
                              steps {
                                  script {
                                      def p4Client = "jenkins-${JOB_NAME}-Sonar"
                                      checkout perforce(credential: "P4",
                                               populate: forceClean(have: true, parallel: [enable: false, minbytes: '1024', minfiles: '1', threads: '4'], pin: '', quiet: true),
                                               workspace: streamSpec(charset: 'none', format: "${p4Client}", pinHost: false, streamName: "//Stream/devStream"))
                                  }
                              }
                              post {
                                  always {
                                      script {
                                          echo "delete P4CLIENT Sonar"
                                          cleanup true
                                      }
                                  }
                              }
                          }
                      } // end parallel
                  }
              } // end stges
          }
          {code}

          I expected both P4CLIENT will be deleted after the job execution, but when I see the log, *ONLY* one is deleted. The log showed that one "cleanup" step didn't get the P4CLIENT correctly. See attachments for details.

          BTW: I checked the P4 code, would the following code be the possible cause?
          p4-plugin\src\main\java\org\jenkinsci\plugins\p4\tagging\TagAction.java
          {code:java}
          /**
          * Find the last action; use this for environment variable as the last action has the latest values.
          *
          * @param run The current build
          * @return Action
          */
          public static TagAction getLastAction(Run<?, ?> run) {
          List<TagAction> actions = lastActions(run);
          if (actions == null) {
          return null;
          }

          // #Review 21165
          TagAction tagAction = run.getAction(TagAction.class);
          for (TagAction t : run.getActions(TagAction.class)) {
          tagAction = (t != null) ? t : tagAction;
          }
          return tagAction;
          }
          {code}


           !screenshot-1.png|thumbnail! !screenshot-2.png|thumbnail!
          New: I have the following pipelines which using parallel stage to checkout source codes from Perforce for Sonar and UT:
          {code:groovy}
          #!/usr/bin/env groovy
          pipeline {
              agent any
              stages {
                  stage('P4 Parallel Checkout Test') {
                      failFast true
                      parallel {
                          stage('UT') {
                              steps {
                                  script {
                                      def p4Client = "jenkins-${JOB_NAME}-UT"
                                      checkout perforce(credential: "P4",
                                               populate: forceClean(have: true, parallel: [enable: false, minbytes: '1024', minfiles: '1', threads: '4'], pin: '', quiet: true),
                                               workspace: streamSpec(charset: 'none', format: "${p4Client}", pinHost: false, streamName: "//Stream/devStream"))
                                    
                                  }
                              }
                              post {
                                  always {
                                      script {
                                          echo "delete P4CLIENT UT"
                                          cleanup true
                                      }
                                  }
                              }
                          }
                          stage('Sonar') {
                              steps {
                                  script {
                                      def p4Client = "jenkins-${JOB_NAME}-Sonar"
                                      checkout perforce(credential: "P4",
                                               populate: forceClean(have: true, parallel: [enable: false, minbytes: '1024', minfiles: '1', threads: '4'], pin: '', quiet: true),
                                               workspace: streamSpec(charset: 'none', format: "${p4Client}", pinHost: false, streamName: "//Stream/devStream"))
                                  }
                              }
                              post {
                                  always {
                                      script {
                                          echo "delete P4CLIENT Sonar"
                                          cleanup true
                                      }
                                  }
                              }
                          }
                      } // end parallel
                  }
              } // end stges
          }
          {code}

          I expected both P4CLIENT will be deleted after the job execution, but when I see the log, *ONLY* one is deleted. The log showed that one "cleanup" step didn't get the P4CLIENT correctly. See attachments for details.

           !screenshot-1.png|thumbnail! !screenshot-2.png|thumbnail!
          Xuezhong Yan made changes -
          Description Original: I have the following pipelines which using parallel stage to checkout source codes from Perforce for Sonar and UT:
          {code:groovy}
          #!/usr/bin/env groovy
          pipeline {
              agent any
              stages {
                  stage('P4 Parallel Checkout Test') {
                      failFast true
                      parallel {
                          stage('UT') {
                              steps {
                                  script {
                                      def p4Client = "jenkins-${JOB_NAME}-UT"
                                      checkout perforce(credential: "P4",
                                               populate: forceClean(have: true, parallel: [enable: false, minbytes: '1024', minfiles: '1', threads: '4'], pin: '', quiet: true),
                                               workspace: streamSpec(charset: 'none', format: "${p4Client}", pinHost: false, streamName: "//Stream/devStream"))
                                    
                                  }
                              }
                              post {
                                  always {
                                      script {
                                          echo "delete P4CLIENT UT"
                                          cleanup true
                                      }
                                  }
                              }
                          }
                          stage('Sonar') {
                              steps {
                                  script {
                                      def p4Client = "jenkins-${JOB_NAME}-Sonar"
                                      checkout perforce(credential: "P4",
                                               populate: forceClean(have: true, parallel: [enable: false, minbytes: '1024', minfiles: '1', threads: '4'], pin: '', quiet: true),
                                               workspace: streamSpec(charset: 'none', format: "${p4Client}", pinHost: false, streamName: "//Stream/devStream"))
                                  }
                              }
                              post {
                                  always {
                                      script {
                                          echo "delete P4CLIENT Sonar"
                                          cleanup true
                                      }
                                  }
                              }
                          }
                      } // end parallel
                  }
              } // end stges
          }
          {code}

          I expected both P4CLIENT will be deleted after the job execution, but when I see the log, *ONLY* one is deleted. The log showed that one "cleanup" step didn't get the P4CLIENT correctly. See attachments for details.

           !screenshot-1.png|thumbnail! !screenshot-2.png|thumbnail!
          New: I have the following pipelines which using parallel stage to checkout source codes from Perforce for Sonar and UT:
          {code:groovy}
          #!/usr/bin/env groovy
          pipeline {
              agent any
              options {
                  timestamps()
                  skipDefaultCheckout()
              }
              stages {
                  stage('P4 Parallel Checkout Test') {
                      failFast true
                      parallel {
                          stage('UT') {
                              steps {
                                  script {
                                      def p4Client = "jenkins-${JOB_NAME}-UT"
                                      checkout perforce(credential: "P4",
                                               populate: forceClean(have: true, parallel: [enable: false, minbytes: '1024', minfiles: '1', threads: '4'], pin: '', quiet: true),
                                               workspace: streamSpec(charset: 'none', format: "${p4Client}", pinHost: false, streamName: "//Stream/devStream"))
                                    
                                  }
                              }
                              post {
                                  always {
                                      script {
                                          echo "delete P4CLIENT UT"
                                          cleanup true
                                      }
                                  }
                              }
                          }
                          stage('Sonar') {
                              steps {
                                  script {
                                      def p4Client = "jenkins-${JOB_NAME}-Sonar"
                                      checkout perforce(credential: "P4",
                                               populate: forceClean(have: true, parallel: [enable: false, minbytes: '1024', minfiles: '1', threads: '4'], pin: '', quiet: true),
                                               workspace: streamSpec(charset: 'none', format: "${p4Client}", pinHost: false, streamName: "//Stream/devStream"))
                                  }
                              }
                              post {
                                  always {
                                      script {
                                          echo "delete P4CLIENT Sonar"
                                          cleanup true
                                      }
                                  }
                              }
                          }
                      } // end parallel
                  }
              } // end stges
          }
          {code}

          I expected both P4CLIENT will be deleted after the job execution, but when I see the log, *ONLY* one is deleted. The log showed that one "cleanup" step didn't get the P4CLIENT correctly. See attachments for details.

           !screenshot-1.png|thumbnail! !screenshot-2.png|thumbnail!

            p4paul Paul Allen
            jackyim Xuezhong Yan
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: