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

Allow workspace to be set via the pipeline build step

    • Icon: Improvement Improvement
    • Resolution: Fixed
    • Icon: Major Major
    • p4-plugin
    • None

      Currently there is no way to unshelve a file for a give workspace. The Current p4unshelve build step pulls the workspace name from the p4scm project defined in the job configuration. This might be a desirable default behavior, but we need to specify a different workspace during our Pipeline job.

       

      Current work-around is to use a 'bat' build step and invoke p4 directly.  

          [JENKINS-42510] Allow workspace to be set via the pipeline build step

          Paul Allen added a comment -

          Do you need different credentials too (username/ticket), or just a different workspace?

          For the moment (1.6.1) you could use p4groovy.  The p4 object requires a workspace and credential, for example (not tested):

          stage 'Unshelve some files' {
              ws = [$class: 'StreamWorkspaceImpl', 
                  charset: 'none', format: wsval, pinHost: false, 
                  streamName: streamval]
          
              // Create P4 object
              p4 = p4(credential: credval, workspace: ws)
              p4.run('unshelve','-f','-s',"${REVIEW}",'-c','default')
          }

          Paul Allen added a comment - Do you need different credentials too (username/ticket), or just a different workspace? For the moment (1.6.1) you could use p4groovy.  The p4 object requires a workspace and credential, for example (not tested): stage 'Unshelve some files' { ws = [$class: 'StreamWorkspaceImpl' , charset: 'none' , format: wsval, pinHost: false , streamName: streamval] // Create P4 object p4 = p4(credential: credval, workspace: ws) p4.run( 'unshelve' , '-f' , '-s' , "${REVIEW}" , '-c' , ' default ' ) }

          Yeah, I would need to specify what credentials i want to use as well (since i may sync/unshelve changes from multiple servers). 

          I will add this our backlog and give it a go when I have a spare moment. 

          Thank for the update

          Peter Anderson added a comment - Yeah, I would need to specify what credentials i want to use as well (since i may sync/unshelve changes from multiple servers).  I will add this our backlog and give it a go when I have a spare moment.  Thank for the update

          I believe I'm being hit by the same issue in 1.6.1.

          Our workflow script uses

          checkout(scm: [$class: 'PerforceScm', ... workspace: [$class: 'ManualWorkspaceImpl', charset: 'none', name: "build_${env.JOB_NAME}_${env.NODE_NAME}", pinHost: true, ...

          to check out the tree on a whole bunch of nodes (as we need to suppress changelog generation and polling). When we call immediately after

           p4unshelve resolve: 'theirs', shelf: params.SHELVED_P4_CHANGELIST_NUMBER

          {{}}, it always uses the workspace of the first checkout that occurred (before the parallel stage). This has only shown up as an issue when there's files being added or deleted in the shelf, as it then refuses to deal with them, and in fact appears to lose the executable flag on them, if present. Otherwise, 'resolve their's appeared to override the overlapping changelist issue.

          Assuming that my problem is correctly part of this issue, I'll try the workaround show above (now that I know what the 'p4' step is for) and see if I can get it to do the right thing there.

          Paul "TBBle" Hampson added a comment - I believe I'm being hit by the same issue in 1.6.1. Our workflow script uses checkout(scm: [$class: 'PerforceScm', ... workspace: [$class: 'ManualWorkspaceImpl', charset: 'none', name: "build_${env.JOB_NAME}_${env.NODE_NAME}", pinHost: true, ... to check out the tree on a whole bunch of nodes (as we need to suppress changelog generation and polling). When we call immediately after p4unshelve resolve: 'theirs', shelf: params.SHELVED_P4_CHANGELIST_NUMBER {{}}, it always uses the workspace of the first checkout that occurred (before the parallel stage). This has only shown up as an issue when there's files being added or deleted in the shelf, as it then refuses to deal with them, and in fact appears to lose the executable flag on them, if present. Otherwise, 'resolve their's appeared to override the overlapping changelist issue. Assuming that my problem is correctly part of this issue, I'll try the workaround show above (now that I know what the 'p4' step is for) and see if I can get it to do the right thing there.

          Paul Allen added a comment -

          Mark as an improvement.

          Add workspace and possibly credentials to unshelve option.
          In addition include unshelved changes in build summary.

          Paul Allen added a comment - Mark as an improvement. Add workspace and possibly credentials to unshelve option. In addition include unshelved changes in build summary.

          Paul "TBBle" Hampson added a comment - - edited

          Note for anyone trying the workaround described in the first comment:
          "${REVIEW}" must be "${REVIEW}".toString(), or script-security-plugin will fail trying to find a method to match, with the same stack-trace as JENKINS-37527.

          The failure is that Array.set cannot coerce a GString into a String.

          I raised JENKINS-44557 against script-security-plugin for the exception requiring toString() to be used.

          Paul "TBBle" Hampson added a comment - - edited Note for anyone trying the workaround described in the first comment: "${REVIEW}" must be "${REVIEW}".toString() , or script-security-plugin will fail trying to find a method to match, with the same stack-trace as JENKINS-37527 . The failure is that Array.set cannot coerce a GString into a String . I raised  JENKINS-44557 against script-security-plugin for the exception requiring toString()  to be used.

          Paul Allen added a comment -

          Added Workspace and Credentials in 1.7.1

          https://swarm.workshop.perforce.com/changes/22315

          Paul Allen added a comment - Added Workspace and Credentials in 1.7.1 https://swarm.workshop.perforce.com/changes/22315

            p4paul Paul Allen
            cryptic2009 Peter Anderson
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: