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

Environment variable replacement on WINDOWS discard backslashes

      Using Declarative Pipeline set environment:

          environment {

                      TEST="$WORKSPACE/test"

                      ...

                      SPEC='linux_x86-64'

                      }

      works fine on linux.

      On Windows 
      WORKSPACE=C:\Users\jenkins\workspace\openjdk_test_x86-64_windows
      TEST will be C:Usersjenkinsworkspaceopenjdk_test_x86-64_windows/test. That is saying passing $WORKSPACE to toString() return discard all backslashes.

      Tried using slash string TEST=/$WORKSPACE/ +'/test' got same issue.

       

          [JENKINS-44482] Environment variable replacement on WINDOWS discard backslashes

          Sophia Guo created issue -
          Sophia Guo made changes -
          Epic Link New: JENKINS-35390 [ 171183 ]

          David Aldrich added a comment - - edited

          Have you tried double backslashes?  For example:

          VSMSBUILDCMD = 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\Common7\\Tools\\VsMSBuildCmd.bat'

           

          David Aldrich added a comment - - edited Have you tried double backslashes?  For example: VSMSBUILDCMD = 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\Common7\\Tools\\VsMSBuildCmd.bat'  

          Raul Khalil added a comment -

          it is not possible to put double backslashes we don´t define the variable. Is there any workaround for this?

          Raul Khalil added a comment - it is not possible to put double backslashes we don´t define the variable. Is there any workaround for this?
          Andrew Bayer made changes -
          Component/s New: pipeline-model-definition-plugin [ 21706 ]
          Component/s Original: pipeline [ 21692 ]
          Andrew Bayer made changes -
          Labels Original: pipeline windows New: declarative-variable-and-method-resolution pipeline windows
          Andrew Bayer made changes -
          Assignee New: Andrew Bayer [ abayer ]

          Andrew Bayer added a comment -

          What version of Declarative do you have installed? I've got tests for this sort of thing in since JENKINS-42748, which went into 1.1.3. I don't have a Windows test env handy, so I can't verify that WORKSPACE gets handled correctly, but if I define an environment variable with backslashes, it does work fine...

          Andrew Bayer added a comment - What version of Declarative do you have installed? I've got tests for this sort of thing in since JENKINS-42748 , which went into 1.1.3. I don't have a Windows test env handy, so I can't verify that WORKSPACE gets handled correctly, but if I define an environment variable with backslashes, it does work fine...
          James Dumay made changes -
          Epic Link Original: JENKINS-35390 [ 171183 ] New: JENKINS-45422 [ 183590 ]

          Andrew Bayer added a comment -

          Turns out the issue is with environment variables that aren't defined in the Jenkinsfile, which is why my existing tests didn't catch this. But conveniently enough, this is fixed by the work for JENKINS-42753, I've added a test to the relevant PR, and it'll be included in the upcoming Declarative 1.2 release.

          Andrew Bayer added a comment - Turns out the issue is with environment variables that aren't defined in the Jenkinsfile , which is why my existing tests didn't catch this. But conveniently enough, this is fixed by the work for JENKINS-42753 , I've added a test to the relevant PR, and it'll be included in the upcoming Declarative 1.2 release.
          Andrew Bayer made changes -
          Link New: This issue depends on JENKINS-42753 [ JENKINS-42753 ]
          Andrew Bayer made changes -
          Resolution New: Fixed [ 1 ]
          Status Original: Open [ 1 ] New: Resolved [ 5 ]

            abayer Andrew Bayer
            sophiag Sophia Guo
            Votes:
            4 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: