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

env.WHATEVER not considered for environment variable cross reference resolution in Declarative

    Details

    • Similar Issues:

      Description

      With an environment section like this:

      environment {
        FOO = "something"
        BAR = "${env.FOO} else"
      }

      The EnvVars-driven environment variable resolution/expansion doesn't know that env.FOO means that it needs to resolve FOO before resolving BAR, so there's no guarantee that'll actually happen in that order, and you may well get BAR as null else.

        Attachments

          Activity

          abayer Andrew Bayer created issue -
          abayer Andrew Bayer made changes -
          Field Original Value New Value
          Status Open [ 1 ] In Progress [ 3 ]
          Hide
          abayer Andrew Bayer added a comment -

          One risk of a fix I've got almost done is that it could turn

          environment {
            FOO = "foo"
            BAR = "${env.FOO} and env.Should not change"
          }

          into BAR == "foo and Should not change" - so I'm poking around to make sure I can do that replacement solely in the curlies.

          Show
          abayer Andrew Bayer added a comment - One risk of a fix I've got almost done is that it could turn environment { FOO = "foo" BAR = "${env.FOO} and env.Should not change" } into BAR == "foo and Should not change" - so I'm poking around to make sure I can do that replacement solely in the curlies.
          Hide
          abayer Andrew Bayer added a comment -

          Got an approach that avoids that. woot.

          Show
          abayer Andrew Bayer added a comment - Got an approach that avoids that. woot.
          abayer Andrew Bayer made changes -
          Status In Progress [ 3 ] Resolved [ 5 ]
          Resolution Fixed [ 1 ]
          Hide
          vtherry Vincent Therry added a comment -

          Hi, 

          I stumbled upon the same issue : 

          This code does not work:

          withEnv([
              "BUILD_TOOLS_FOLDER=${env.WORKSPACE}\\BuildTools",
              "PATH+NUGET=${env.BUILD_TOOLS_FOLDER}\\NuGet"])
          {
              echo "${BUILD_TOOLS_FOLDER}" => echo c:\J\workspace\master400f232c\BuildTools
              echo "${PATH}" => echo null\NuGet;...PATH...
          }

           

          While this code works

          withEnv(["BUILD_TOOLS_FOLDER=${env.WORKSPACE}\\BuildTools"]){
              withEnv(["PATH+NUGET=${env.BUILD_TOOLS_FOLDER}\\NuGet"]){
                  echo "${BUILD_TOOLS_FOLDER}" => echo c:\J\workspace\master400f232c\BuildTools
                  echo "${PATH}" => echo c:\J\workspace\master400f232c\BuildTools\NuGet;...PATH...
              }
          }
          Show
          vtherry Vincent Therry added a comment - Hi,  I stumbled upon the same issue :  This code does not work: withEnv([     "BUILD_TOOLS_FOLDER=${env.WORKSPACE}\\BuildTools" ,     "PATH+NUGET=${env.BUILD_TOOLS_FOLDER}\\NuGet" ]) {     echo "${BUILD_TOOLS_FOLDER}" => echo c:\J\workspace\master400f232c\BuildTools     echo "${PATH}" => echo null \NuGet;...PATH... }   While this code works withEnv([ "BUILD_TOOLS_FOLDER=${env.WORKSPACE}\\BuildTools" ]){     withEnv([ "PATH+NUGET=${env.BUILD_TOOLS_FOLDER}\\NuGet" ]){         echo "${BUILD_TOOLS_FOLDER}" => echo c:\J\workspace\master400f232c\BuildTools         echo "${PATH}" => echo c:\J\workspace\master400f232c\BuildTools\NuGet;...PATH...     } }
          Hide
          abayer Andrew Bayer added a comment -

          What version of pipeline-model-definition do you have installed?

          Show
          abayer Andrew Bayer added a comment - What version of pipeline-model-definition do you have installed?
          Hide
          vtherry Vincent Therry added a comment -

          I have version 1.1.2 installed

          All plugins are up to date

          Show
          vtherry Vincent Therry added a comment - I have version 1.1.2 installed All plugins are up to date
          Hide
          abayer Andrew Bayer added a comment -

          Ah, didn't notice that you were using withEnv. That's not a Declarative issue - open a ticket against workflow-basic-steps.

          Show
          abayer Andrew Bayer added a comment - Ah, didn't notice that you were using withEnv. That's not a Declarative issue - open a ticket against workflow-basic-steps.
          Hide
          vtherry Vincent Therry added a comment -

          Also I noticed I cannot set environment variables like that (I work on Windows) :

           

          environment {
              PATH_TO_MY_WINDOWS_FOLDER = "C:\\MyFolder"
          }
          

           

          I am getting the following error : 

          hudson.remoting.ProxyException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
          http://jenkins.eureka.lan:8080/blue/organizations/jenkins/DispatchAdminApi%2FDispatchAdminApi/detail/master/149/pipeline#log-25Script4.groovy: 1: unexpected char: '\' @ line 1, column 30.
          http://jenkins.eureka.lan:8080/blue/organizations/jenkins/DispatchAdminApi%2FDispatchAdminApi/detail/master/149/pipeline#log-26 "PATH_TO_MY_WINDOWS_FOLDER=C:\MyFolder"

          Show
          vtherry Vincent Therry added a comment - Also I noticed I cannot set environment variables like that (I work on Windows) :   environment {     PATH_TO_MY_WINDOWS_FOLDER = "C:\\MyFolder" }   I am getting the following error :  hudson.remoting.ProxyException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: http://jenkins.eureka.lan:8080/blue/organizations/jenkins/DispatchAdminApi%2FDispatchAdminApi/detail/master/149/pipeline#log-25 Script4.groovy: 1: unexpected char: '\' @ line 1, column 30. http://jenkins.eureka.lan:8080/blue/organizations/jenkins/DispatchAdminApi%2FDispatchAdminApi/detail/master/149/pipeline#log-26 "PATH_TO_MY_WINDOWS_FOLDER=C:\MyFolder"
          Hide
          abayer Andrew Bayer added a comment -

          Yes, known bug - JENKINS-42748

          Show
          abayer Andrew Bayer added a comment - Yes, known bug -  JENKINS-42748
          Hide
          vtherry Vincent Therry added a comment -

          Ok, Thank you, my JiraFu seems broken

          I'll open an issue for my previous case when I will have the time.

           

          Show
          vtherry Vincent Therry added a comment - Ok, Thank you, my JiraFu seems broken I'll open an issue for my previous case when I will have the time.  
          Hide
          bitwiseman Liam Newman added a comment -

          Bulk closing resolved issues.

          Show
          bitwiseman Liam Newman added a comment - Bulk closing resolved issues.
          bitwiseman Liam Newman made changes -
          Status Resolved [ 5 ] Closed [ 6 ]

            People

            • Assignee:
              abayer Andrew Bayer
              Reporter:
              abayer Andrew Bayer
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: