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

[P4 Plugin] P4_ROOT is not set properly - pointing to build workspace instead of p4 client root

      The following problem was observed in a pipeline type job:

      After the perforce scm step is executed the P4_ROOT environment variable is not set properly. It is pointing to the build workspace instead of the p4 client root of the client used during the scm step. I have tested it using static workspace behavior and the p4 preview option. Basically the P4_ROOT is the same as WORKSPACE environment variable, but it should be set to p4 clients root.

       

      agent{
        node{
            label "node1"
            customWorkspace "C:\\Custom\\BuildWorkspacePath"
        }
      }
      stages{
        stage('Test'){
          steps{
            // Perforce client myP4Client has p4 root set to C:\\myP4Client
            checkout perforce(credential: 'myP4Creds', populate: previewOnly(quiet: true), workspace: staticSpec(charset: 'none', name: 'myP4Client', pinHost: false))
            // P4_ROOT will be set to "C:\\Custom\\BuildWorkspacePath" instead of "C:\\myP4Client"
            echo "${currentBuild.rawBuild.getEnvironment()}"
          }
        }
      }
      
      

          [JENKINS-64707] [P4 Plugin] P4_ROOT is not set properly - pointing to build workspace instead of p4 client root

          Piotr Ławniczuk created issue -
          Piotr Ławniczuk made changes -
          Labels New: P4_ROOT
          Piotr Ławniczuk made changes -
          Labels Original: P4_ROOT New: EnvironmentalVariable P4_ROOT
          Piotr Ławniczuk made changes -
          Labels Original: EnvironmentalVariable P4_ROOT New: EnvironmentalVariable P4_ROOT environment-variables
          Piotr Ławniczuk made changes -
          Description Original: The following problem was observed in a pipeline type job:

          After the perforce scm step is executed the P4_ROOT environment variable is not set properly. It is pointing to the build workspace instead of the p4 client root of the client used during the scm step. I have tested it using static workspace behavior and the p4 preview option. Basically the P4_ROOT is the same as WORKSPACE environment variable, but it should be set to p4 clients root.
          New: The following problem was observed in a pipeline type job:

          After the perforce scm step is executed the P4_ROOT environment variable is not set properly. It is pointing to the build workspace instead of the p4 client root of the client used during the scm step. I have tested it using static workspace behavior and the p4 preview option. Basically the P4_ROOT is the same as WORKSPACE environment variable, but it should be set to p4 clients root.

           
          {code:java}
              agent{
                  node{
                      label "master"
                  }
              }
              parameters{
                  string (name: 'change', defaultValue: '', trim: true, description: '')
                  string (name: 'shelve', defaultValue: '', trim: true, description: '')
              }
              options{
                  buildDiscarder logRotator(numToKeepStr: '5')
                  timestamps()
              }
              stages{
                  stage('first'){
                      steps{
                          checkout perforce(credential: 'robot.obibok_1777', populate: previewOnly(quiet: true), workspace: staticSpec(charset: 'none', name: 'robot.obibok_IDK300_TESTSTREAM_development', pinHost: false))
                          echo "${currentBuild.rawBuild.getEnvironment()}"
                          setupPipeline(displayName: "test", description: "PS4")
                      }
                  }
              }
          }
          {code}
          Piotr Ławniczuk made changes -
          Description Original: The following problem was observed in a pipeline type job:

          After the perforce scm step is executed the P4_ROOT environment variable is not set properly. It is pointing to the build workspace instead of the p4 client root of the client used during the scm step. I have tested it using static workspace behavior and the p4 preview option. Basically the P4_ROOT is the same as WORKSPACE environment variable, but it should be set to p4 clients root.

           
          {code:java}
              agent{
                  node{
                      label "master"
                  }
              }
              parameters{
                  string (name: 'change', defaultValue: '', trim: true, description: '')
                  string (name: 'shelve', defaultValue: '', trim: true, description: '')
              }
              options{
                  buildDiscarder logRotator(numToKeepStr: '5')
                  timestamps()
              }
              stages{
                  stage('first'){
                      steps{
                          checkout perforce(credential: 'robot.obibok_1777', populate: previewOnly(quiet: true), workspace: staticSpec(charset: 'none', name: 'robot.obibok_IDK300_TESTSTREAM_development', pinHost: false))
                          echo "${currentBuild.rawBuild.getEnvironment()}"
                          setupPipeline(displayName: "test", description: "PS4")
                      }
                  }
              }
          }
          {code}
          New: The following problem was observed in a pipeline type job:

          After the perforce scm step is executed the P4_ROOT environment variable is not set properly. It is pointing to the build workspace instead of the p4 client root of the client used during the scm step. I have tested it using static workspace behavior and the p4 preview option. Basically the P4_ROOT is the same as WORKSPACE environment variable, but it should be set to p4 clients root.

           
          {code:java}
          agent{
            node{
                label "node1"
                customWorkspace "C:\\Custom\\BuildWorkspacePath"
            }
          }
          stages{
            stage('Test'){
              steps{
                  // Perforce client myP4Client has p4 root set to C:\\myP4Client
                  checkout perforce(credential: 'myP4Creds', populate: previewOnly(quiet: true), workspace: staticSpec(charset: 'none', name: 'myP4Client', pinHost: false))
                  // P4_ROOT will be set to "C:\\Custom\\BuildWorkspacePath" instead of "C:\\myP4Client"
                  echo "${currentBuild.rawBuild.getEnvironment()}"
              }
            }
          }

          {code}
          Piotr Ławniczuk made changes -
          Description Original: The following problem was observed in a pipeline type job:

          After the perforce scm step is executed the P4_ROOT environment variable is not set properly. It is pointing to the build workspace instead of the p4 client root of the client used during the scm step. I have tested it using static workspace behavior and the p4 preview option. Basically the P4_ROOT is the same as WORKSPACE environment variable, but it should be set to p4 clients root.

           
          {code:java}
          agent{
            node{
                label "node1"
                customWorkspace "C:\\Custom\\BuildWorkspacePath"
            }
          }
          stages{
            stage('Test'){
              steps{
                  // Perforce client myP4Client has p4 root set to C:\\myP4Client
                  checkout perforce(credential: 'myP4Creds', populate: previewOnly(quiet: true), workspace: staticSpec(charset: 'none', name: 'myP4Client', pinHost: false))
                  // P4_ROOT will be set to "C:\\Custom\\BuildWorkspacePath" instead of "C:\\myP4Client"
                  echo "${currentBuild.rawBuild.getEnvironment()}"
              }
            }
          }

          {code}
          New: The following problem was observed in a pipeline type job:

          After the perforce scm step is executed the P4_ROOT environment variable is not set properly. It is pointing to the build workspace instead of the p4 client root of the client used during the scm step. I have tested it using static workspace behavior and the p4 preview option. Basically the P4_ROOT is the same as WORKSPACE environment variable, but it should be set to p4 clients root.

           
          {code:java}
          agent{
            node{
                label "node1"
                customWorkspace "C:\\Custom\\BuildWorkspacePath"
            }
          }
          stages{
            stage('Test'){
              steps{
                // Perforce client myP4Client has p4 root set to C:\\myP4Client
                checkout perforce(credential: 'myP4Creds', populate: previewOnly(quiet: true), workspace: staticSpec(charset: 'none', name: 'myP4Client', pinHost: false))
                // P4_ROOT will be set to "C:\\Custom\\BuildWorkspacePath" instead of "C:\\myP4Client"
                echo "${currentBuild.rawBuild.getEnvironment()}"
              }
            }
          }

          {code}

          Karl Wirth added a comment -

          Hi plawniczuk . At the moment you cannot set a workspace root as you have found because the build needs to be done under the Jenkins workspace root. In the past I have recomended using the 'ws' directive. For example I give an example here:

           

               https://issues.jenkins.io/browse/JENKINS-47005

           

          Is 'customWorkspace' different to 'ws'? Can you please try 'ws' and see if that solves the problem. Also note that if you are using multiple build slaves and the build can run on any slave please ensure that the node name and job appear in the client name of any real scripts. For example:

              jenkins-${NODE_NAME}${JOB_NAME}${EXECUTOR_NUMBER}

           

           

          Karl Wirth added a comment - Hi plawniczuk . At the moment you cannot set a workspace root as you have found because the build needs to be done under the Jenkins workspace root. In the past I have recomended using the 'ws' directive. For example I give an example here:        https://issues.jenkins.io/browse/JENKINS-47005   Is 'customWorkspace' different to 'ws'? Can you please try 'ws' and see if that solves the problem. Also note that if you are using multiple build slaves and the build can run on any slave please ensure that the node name and job appear in the client name of any real scripts. For example:     jenkins-${NODE_NAME} ${JOB_NAME} ${EXECUTOR_NUMBER}    

          Hi Karl,

          'customWorkspace' and 'ws' is basically the same, it will allocate the workspace with given path and the result will be the same as I described it in my ticket: P4_ROOT will point to the value of WORKSPACE env var. 

          I think I did not explain my scenario good enough and the use case in which this behavior is problematic. In our pipelines we use mostly static workspace's and preview as an operation. The rest of p4 operations like: sync, unshelve, revert etc. is done by the bat steps and p4 cli tool, as we would like to have total control of all perforce related operations. We use P4 Plugin mostly to read the head of the client and for all the Jenkins changelog related features. We now have a scenario where workspaces are located inside the folder junctions and p4 operations fails due to wrong pwd (Symbolic Links and Workspace Roots), so getting the real p4 client root with use of plugin in P4_ROOT env var would be really helpful here.

          It means also also that description for P4_ROOT is very misleading (from P4 Plugin documentation):

          P4_ROOT - The Perforce client workspace root path.
          

          It is not perforce client workspace root path, it is the Jenkins build workspace root path.

          Piotr Ławniczuk added a comment - Hi Karl, 'customWorkspace' and 'ws' is basically the same, it will allocate the workspace with given path and the result will be the same as I described it in my ticket: P4_ROOT will point to the value of WORKSPACE env var.  I think I did not explain my scenario good enough and the use case in which this behavior is problematic. In our pipelines we use mostly static workspace's and preview as an operation. The rest of p4 operations like: sync, unshelve, revert etc. is done by the bat steps and p4 cli tool, as we would like to have total control of all perforce related operations. We use P4 Plugin mostly to read the head of the client and for all the Jenkins changelog related features. We now have a scenario where workspaces are located inside the folder junctions and p4 operations fails due to wrong pwd ( Symbolic Links and Workspace Roots ), so getting the real p4 client root with use of plugin in P4_ROOT env var would be really helpful here. It means also also that description for P4_ROOT is very misleading (from P4 Plugin documentation): P4_ROOT - The Perforce client workspace root path. It is not perforce client workspace root path, it is the Jenkins build workspace root path.
          Karl Wirth made changes -
          Link New: This issue is caused by JENKINS-47005 [ JENKINS-47005 ]

            Unassigned Unassigned
            plawniczuk Piotr Ławniczuk
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: