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

EnvJect unsets empty string properties returned in maps

    Details

    • Type: Bug
    • Status: Reopened (View Workflow)
    • Priority: Blocker
    • Resolution: Unresolved
    • Component/s: envinject-plugin
    • Labels:
      None
    • Environment:
      1.69, 1.92.1
    • Similar Issues:

      Description

      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.

        Attachments

          Issue Links

            Activity

            Hide
            gbois Gregory Boissinot added a comment -

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

            Show
            gbois Gregory Boissinot added a comment - Are you sure want to not remove empty environment variables? What are your use cases?
            Hide
            jmaxwell Jeff Maxwell added a comment -

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

            Show
            jmaxwell Jeff Maxwell added a comment - We need to blank a variable (a perforce label) based on certain combinations of user input.
            Hide
            jmaxwell 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}

            Show
            jmaxwell 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}
            Hide
            scm_issue_link 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

            Show
            scm_issue_link 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
            Hide
            gbois Gregory Boissinot added a comment -

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

            Show
            gbois Gregory Boissinot added a comment - Sorry for the inconvenience. Empty environment variables are acceptable for now.
            Hide
            jbochenski Jakub Bochenski added a comment -

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

            Show
            jbochenski Jakub Bochenski added a comment - I'm getting the same behaviour (blank properties are not set) in 1.92.1
            Hide
            think 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.

            Show
            think 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.
            Hide
            tisis2 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...

            Show
            tisis2 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...
            Hide
            jglick Jesse Glick added a comment -

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

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

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

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

              People

              • Assignee:
                gbois Gregory Boissinot
                Reporter:
                jmaxwell Jeff Maxwell
              • Votes:
                6 Vote for this issue
                Watchers:
                15 Start watching this issue

                Dates

                • Created:
                  Updated: