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

Expose the ability to use an existing p4 client (workspace)

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • p4-plugin
    • None

      I have been using p4groovy with Jenkins pipelines for a while now, and this is becoming more and more cumbersome.

      In order to instantiate a p4 object (to run any sort of p4 command), you must define a workspace which p4groovy attempts to create. There doesn't seem to be a way (that I can tell) to just use an existing workspace.

      Here is an example of why this is cumbersome. I have a shared function called `get_latest_change()` which simply runs the command `p4 changes -m1 //depot/...`. This command doesn't need a workspace to run, but since p4groovy seems to require one, I have to manually instantiate a workspace and pass it into the function every time I want to call it (and I need to go to great pains to make sure the ws object I create matches the existing workspace so I don't accidentally change things).

          [JENKINS-49967] Expose the ability to use an existing p4 client (workspace)

          Paul Allen added a comment -

          Have you tried 'Static Workspace' or 'Spec File'?

          https://github.com/jenkinsci/p4-plugin/blob/master/SETUP.md

          Paul Allen added a comment - Have you tried 'Static Workspace' or 'Spec File'? https://github.com/jenkinsci/p4-plugin/blob/master/SETUP.md

          Jay Spang added a comment -

          According to the docs, static view still updates the client to what Jenkins thinks it should be. I don't want Jenkins to change anything on the workspace, just use it. Here's a common bug I recently had to fix:

          Steps:

          1. In Jenkins pipeline, cd into some dir other than root
          2. Use p4groovy to run some command. In my bug, it was "p4 changes -m1" to get the most recent changelist.

          P4groovy will change the workspace root to whatever dir you're cd'd into. This causes a very subtle bug that's hard to find, as multiple copies of the workspace get sycned to multiple directories.

          I fully admit this is an advanced topic only relevant to scripting with p4groovy, but this somewhat unexpected behavior caused several bugs as I was setting things up.

          Jay Spang added a comment - According to the docs, static view still updates the client to what Jenkins thinks it should be. I don't want Jenkins to change anything on the workspace, just  use  it. Here's a common bug I recently had to fix: Steps: In Jenkins pipeline, cd into some dir other than root Use p4groovy to run some command. In my bug, it was "p4 changes -m1" to get the most recent changelist. P4groovy will  change  the workspace root to whatever dir you're cd'd into. This causes a very subtle bug that's hard to find, as multiple copies of the workspace get sycned to multiple directories. I fully admit this is an advanced topic only relevant to scripting with p4groovy, but this somewhat unexpected behavior caused several bugs as I was setting things up.

          Paul Allen added a comment -

          I'm not sure it is possible to fix as the Perforce client root is tightly coupled to the Jenkins workspace root.  Are you able to remaining at the workspace root and use Perforce Depot, Client or relative Local syntax for the p4groovy operations. e.g.

          Local syntax:  "p4 change -m1 sub2/..."

          Client syntax:  "p4 change -m1 //client_name/sub2/..."

          Depot syntax:  "p4 change -m1 //depot/projectX/sub2/..."

          Paul Allen added a comment - I'm not sure it is possible to fix as the Perforce client root is tightly coupled to the Jenkins workspace root.  Are you able to remaining at the workspace root and use Perforce Depot, Client or relative Local syntax for the p4groovy operations. e.g. Local syntax:  "p4 change -m1 sub2/..." Client syntax:  "p4 change -m1 //client_name/sub2/..." Depot syntax:  "p4 change -m1 //depot/projectX/sub2/..."

            Unassigned Unassigned
            jayspang Jay Spang
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: