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

ws step does not update WORKSPACE environment variable

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      I consider this a bug, but feel free to reclassify.

      node {
          ws ('workspace/customDir') {
              println "workspace: ${env.WORKSPACE}"
          }
      }
      
      [Pipeline] node
      Running on <node> in E:\JenkinsRoot\workspace\Experiments\Test_Workspace
      [Pipeline] {
      [Pipeline] ws
      Running in E:\JenkinsRoot\workspace\customDir
      [Pipeline] {
      [Pipeline] echo
      workspace: E:\JenkinsRoot\workspace\Experiments\Test_Workspace
      [Pipeline] }
      [Pipeline] // ws
      [Pipeline] }
      [Pipeline] // node
      [Pipeline] End of Pipeline
      Finished: SUCCESS
      

      I can't find a way, in code, to get the path to the workspace after using the ws step. At the moment the only way I've found is to run a batch or shell script and get the current working directory from there.

      Please tell me if I'm missing something

        Attachments

          Activity

          Hide
          blatinville Bertrand Latinville added a comment - - edited

          I was about to open this issue, I faced it yesterday.

          I had a look in the code of WorkspaceStepExecution.java and tried to inject the new workspace path value in the environment, with
          this commit:

          https://github.com/blatinville/workflow-durable-task-step-plugin/commit/80886255fb283f272a1726001a37989185f7a9e4

          Using this pipeline:

          stage ("Test Workspace") {
              node ('linux') {
                  sh "echo node=\${NODE_NAME},  WORKSPACE=\${WORKSPACE}"
                  ws('foo')
                  {
                      sh "echo node=\${NODE_NAME},  WORKSPACE=\${WORKSPACE}"
                  
                  }
              }
          }
          

          WORKSPACE is correct after, BUT, NODE_NAME is set to null in the ws() step.
          Need to find something better.

          Show
          blatinville Bertrand Latinville added a comment - - edited I was about to open this issue, I faced it yesterday. I had a look in the code of WorkspaceStepExecution.java and tried to inject the new workspace path value in the environment, with this commit: https://github.com/blatinville/workflow-durable-task-step-plugin/commit/80886255fb283f272a1726001a37989185f7a9e4 Using this pipeline: stage ( "Test Workspace" ) { node ( 'linux' ) { sh "echo node=\${NODE_NAME}, WORKSPACE=\${WORKSPACE}" ws( 'foo' ) { sh "echo node=\${NODE_NAME}, WORKSPACE=\${WORKSPACE}" } } } WORKSPACE is correct after, BUT, NODE_NAME is set to null in the ws() step. Need to find something better.
          Hide
          jglick Jesse Glick added a comment -

          Would make sense to do it. Bertrand Latinville I think you meant to use EnvironmentExpander.

          Anyway $WORKSPACE is just there for conceptual compatibility with freestyle projects. Definitely would not want to set it inside the dir step. Use pwd() if you want to know the current working directory.

          Show
          jglick Jesse Glick added a comment - Would make sense to do it. Bertrand Latinville I think you meant to use EnvironmentExpander . Anyway $WORKSPACE is just there for conceptual compatibility with freestyle projects. Definitely would not want to set it inside the dir step. Use pwd() if you want to know the current working directory.
          Hide
          blatinville Bertrand Latinville added a comment -

          Our shell scripts, use the $WORKSPACE variable, so it is better so have it set properly by default, to use pipeline without modifications.

          Associated PR : https://github.com/jenkinsci/workflow-durable-task-step-plugin/pull/29

          Show
          blatinville Bertrand Latinville added a comment - Our shell scripts, use the $WORKSPACE variable, so it is better so have it set properly by default, to use pipeline without modifications. Associated PR : https://github.com/jenkinsci/workflow-durable-task-step-plugin/pull/29

            People

            • Assignee:
              blatinville Bertrand Latinville
              Reporter:
              philmcardlecg Phil McArdle
            • Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: