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 added a comment -

          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

          	/**
          	 * 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;
          	}
          

          Xuezhong Yan added a comment - 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 /** * 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; }

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

              Created:
              Updated: