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

Allow workspace to be set via the pipeline build step

    Details

    • Type: Improvement
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Fixed
    • Component/s: p4-plugin
    • Labels:
      None
    • Similar Issues:

      Description

      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.  

        Attachments

          Issue Links

            Activity

            Hide
            p4paul 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')
            }
            Show
            p4paul 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 ' ) }
            Hide
            cryptic2009 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

            Show
            cryptic2009 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
            Hide
            p_hampson 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.

            Show
            p_hampson 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.
            Hide
            p4paul 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.

            Show
            p4paul 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.
            Hide
            p_hampson 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.

            Show
            p_hampson 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.
            Hide
            p4paul Paul Allen added a comment -

            Added Workspace and Credentials in 1.7.1

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

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

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved: