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

EnvJect unsets empty string properties returned in maps

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Blocker Blocker
    • envinject-plugin
    • None
    • 1.69, 1.92.1

      EnvJect unsets empty and whitespace properties

      Example
      return ["LABEL":" ",ANOTHER_LABEL:""]

      [EnvInject] - Unset unresolved 'ANOTHER_LABEL' variable.
      [EnvInject] - Unset unresolved 'LABEL' variable.

      It appears that the fix for JENKINS-14930 caused the problem.

      Unsetting blank variables should be optional.

          [JENKINS-15146] EnvJect unsets empty string properties returned in maps

          Are you sure want to not remove empty environment variables?
          What are your use cases?

          Gregory Boissinot added a comment - Are you sure want to not remove empty environment variables? What are your use cases?

          Jeff Maxwell added a comment -

          We need to blank a variable (a perforce label) based on certain combinations of user input.

          Jeff Maxwell added a comment - We need to blank a variable (a perforce label) based on certain combinations of user input.

          Jeff Maxwell added a comment -

          Another example: We need to add maven profiles only certain combinations of user input.
          In the example below ${MAVEN_PROPERTIES} and ${MAVEN_PROFILES} need to be blank under certain circumstances.

          Build:
          Goals and options: ${MAVEN_GOALS} ${MAVEN_PROPERTIES} ${MAVEN_PROFILES}

          Jeff Maxwell added a comment - Another example: We need to add maven profiles only certain combinations of user input. In the example below ${MAVEN_PROPERTIES} and ${MAVEN_PROFILES} need to be blank under certain circumstances. Build: Goals and options: ${MAVEN_GOALS} ${MAVEN_PROPERTIES} ${MAVEN_PROFILES}

          Code changed in jenkins
          User: Gregory Boissinot
          Path:
          src/main/java/org/jenkinsci/plugins/envinject/service/EnvInjectEnvVars.java
          src/test/java/org/jenkinsci/plugins/envinject/EnvInjectEnvVarsEmpty.java
          http://jenkins-ci.org/commit/envinject-plugin/718586449693a86314242223b14813c374b8bbdc
          Log:
          Fix JENKINS-15146

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Gregory Boissinot Path: src/main/java/org/jenkinsci/plugins/envinject/service/EnvInjectEnvVars.java src/test/java/org/jenkinsci/plugins/envinject/EnvInjectEnvVarsEmpty.java http://jenkins-ci.org/commit/envinject-plugin/718586449693a86314242223b14813c374b8bbdc Log: Fix JENKINS-15146

          Sorry for the inconvenience.
          Empty environment variables are acceptable for now.

          Gregory Boissinot added a comment - Sorry for the inconvenience. Empty environment variables are acceptable for now.

          I'm getting the same behaviour (blank properties are not set) in 1.92.1

          Jakub Bochenski added a comment - I'm getting the same behaviour (blank properties are not set) in 1.92.1

          think think added a comment -

          it's still not possible to have an empty Environment variable.
          Using pipeline step withEnv(['FOO=']) with result in key="FOO" and value="".
          Then EnvVars.override is called and even removes "FOO" from Environment.

          https://github.com/kohsuke/hudson/blob/master/core/src/main/java/hudson/EnvVars.java#L126

          if(value==null || value.length()==0) {
              remove(key);
              return;
          }
          

          The behavior would be okay, if the value is null. But for an explicit empty String it seems not reasonable, that the Key is deleted.

          What needs to be done to change this? It could not be done in the withEnv Code except in dirty ways.

          think think added a comment - it's still not possible to have an empty Environment variable. Using pipeline step withEnv( ['FOO='] ) with result in key="FOO" and value="". Then EnvVars.override is called and even removes "FOO" from Environment. https://github.com/kohsuke/hudson/blob/master/core/src/main/java/hudson/EnvVars.java#L126 if (value== null || value.length()==0) { remove(key); return ; } The behavior would be okay, if the value is null. But for an explicit empty String it seems not reasonable, that the Key is deleted. What needs to be done to change this? It could not be done in the withEnv Code except in dirty ways.

          we use it for parameters to give the starter of a job the possibility to extend an existing path with a subpath. if the starter wants to use the root he wont type anything for this parameter... this doesn't work anymore...

          Dominik Gabriel added a comment - we use it for parameters to give the starter of a job the possibility to extend an existing path with a subpath. if the starter wants to use the root he wont type anything for this parameter... this doesn't work anymore...

          Jesse Glick added a comment -

          think Pipeline does not use EnvInject so any Pipeline bug should be filed separately with steps to reproduce from scratch, in workflow-plugin.

          Jesse Glick added a comment - think Pipeline does not use EnvInject so any Pipeline bug should be filed separately with steps to reproduce from scratch, in workflow-plugin .

          Jason Zheng added a comment -

          I want to set a environment variable to an empty string ("") via withEnv(), but it seems not working.

          Jason Zheng added a comment - I want to set a environment variable to an empty string ("") via withEnv(), but it seems not working.

            gbois Gregory Boissinot
            jmaxwell Jeff Maxwell
            Votes:
            7 Vote for this issue
            Watchers:
            15 Start watching this issue

              Created:
              Updated: