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

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

    XMLWordPrintable

Details

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

          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.
          abayer Andrew Bayer added a comment -

          Got an approach that avoids that. woot.

          abayer Andrew Bayer added a comment - Got an approach that avoids that. woot.

          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...
              }
          }
          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...     } }
          abayer Andrew Bayer added a comment -

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

          abayer Andrew Bayer added a comment - What version of pipeline-model-definition do you have installed?

          I have version 1.1.2 installed

          All plugins are up to date

          vtherry Vincent Therry added a comment - I have version 1.1.2 installed All plugins are up to date
          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.

          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.

          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"

          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"
          abayer Andrew Bayer added a comment -

          Yes, known bug - JENKINS-42748

          abayer Andrew Bayer added a comment - Yes, known bug -  JENKINS-42748

          Ok, Thank you, my JiraFu seems broken

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

           

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

          Bulk closing resolved issues.

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

          People

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

            Dates

              Created:
              Updated:
              Resolved: