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

Environment variable replacement on WINDOWS discard backslashes

    XMLWordPrintable

Details

    Description

      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.

       

      Attachments

        Issue Links

          Activity

            davida2009 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'

             

            davida2009 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'  
            rkhalil 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?

            rkhalil 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?
            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...

            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...
            abayer 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.

            abayer 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.
            bitwiseman Liam Newman added a comment -

            Bulk closing resolved issues.

            bitwiseman Liam Newman added a comment - Bulk closing resolved issues.

            People

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

              Dates

                Created:
                Updated:
                Resolved: