Testing the latest version of the pipeline plugins and it appears that it's no longer possible to set empty environment variables.  The following works in some current declarative scripts I have still using v1.0.2:

      pipeline{
          environment{
             EMAIL_RECIPIENTS         = 'me@me.com' 
             EMAIL_RECIPIENTS_SUCCESS = ''
          }
          
          (some stages and steps)
      
          post {
              success {
                  echo 'Send Success message...'
                  buildEmailer (currentBuild.result, EMAIL_RECIPIENTS, EMAIL_RECIPIENTS_SUCCESS)
              }
              failure {
                  echo 'Send Failed message...'
                  buildEmailer (currentBuild.result, EMAIL_RECIPIENTS, EMAIL_RECIPIENTS_SUCCESS) 
              } 
          }
      }

      I have emailing logic in shared library (buildEmailer) and do some processing if the incoming variable is blank. The above causes no trouble in plugin version 1.0.2, but in 1.1.2, I get:

      groovy.lang.MissingPropertyException: No such property: EMAIL_RECIPIENTS_SUCCESS for class: WorkflowScript
      at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:53)
      at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.getProperty(ScriptBytecodeAdapter.java:458)
      at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.getProperty(DefaultInvoker.java:33)
      at com.cloudbees.groovy.cps.impl.PropertyAccessBlock.rawGet(PropertyAccessBlock.java:20)
      at WorkflowScript.run(WorkflowScript:127)
      ...

      However, the script is OK if I move things around and set the variables inside a script {} section inside a stage{}. The reason this particular value is set but blank, is that I let this value be optional and let developers update the desired property to what they want in the build job. I could process some default value in the environment section, but since the scripts works with variables in a script section, and it was working in 1.0.2, it seems like this could be a bug with the environment section.

          [JENKINS-43632] Not Possible to Set Blank Environment Variables

          vishal kumar added a comment -

          jedavis:- May i know how did you fix this in your pipeline, because if i am trying to set a variable empty by default it takes the value  "null" and passed everywhere.

          vishal kumar added a comment - jedavis :- May i know how did you fix this in your pipeline, because if i am trying to set a variable empty by default it takes the value  "null" and passed everywhere.

          Vote for this issue is disabled for me.  Please count this as my +1 - Blue ocean USER INTERFACE should not drive the requirements for how a program displays its data - it should respond to the needs of the users and accommodate the use cases that customers need.  Clearly if the job description allows HTML for normal Jenkins use - then BO should accommodate this.

          Todd Lindstrom added a comment - Vote for this issue is disabled for me.  Please count this as my +1 - Blue ocean USER INTERFACE should not drive the requirements for how a program displays its data - it should respond to the needs of the users and accommodate the use cases that customers need.  Clearly if the job description allows HTML for normal Jenkins use - then BO should accommodate this.

          I would also consider this a bug. Environment variables with an empty string should be possible. It is not the same as unset.

          Christian Schneider added a comment - I would also consider this a bug. Environment variables with an empty string should be possible. It is not the same as unset.

          Any update on this? This is clear a bug and a problem! I had to do some crazy things to work around such a basic thing...

          Guillaume Egles added a comment - Any update on this? This is clear a bug and a problem! I had to do some crazy things to work around such a basic thing...

          Volker von Einem added a comment - - edited

          Same here...

          I wanted something like this: 
          VERSION_SUFFIX = "${env.BRANCH_NAME == "master" ? "" : "-alpha"}"
          It fails without information about the problem.
          Is there a workaround?

           

          Update:

          A workaround - not nice - that worked for me aw to use a blank " ".
          VERSION_SUFFIX = "${env.BRANCH_NAME == "master" ? " " : "-alpha"}"

          Volker von Einem added a comment - - edited Same here... I wanted something like this:  VERSION_SUFFIX = "${env.BRANCH_NAME == "master" ? "" : "-alpha"}" It fails without information about the problem. Is there a workaround?   Update: A workaround - not nice - that worked for me aw to use a blank " ". VERSION_SUFFIX = "${env.BRANCH_NAME == "master" ? " " : "-alpha"}"

          Pablo Chacin added a comment -

          As others have already said, this should be considered a bug. Environment variables can be set to empty value. It is a common practice. Not allowing it limits the interoperability with existing scripts that make a distinction between not set an empty. 

          Pablo Chacin added a comment - As others have already said, this should be considered a bug. Environment variables can be set to empty value. It is a common practice. Not allowing it limits the interoperability with existing scripts that make a distinction between not set an empty. 

          Caio Reis added a comment -

          I´m having same problem for a pipeline in my company

          And let the variable with white space " " is not a option.

          Any other thoughts? 

          Caio Reis added a comment - I´m having same problem for a pipeline in my company And let the variable with white space " " is not a option. Any other thoughts? 

          vad vad added a comment -

          The current work around is set the variable to space then replace space with empty later in pipeline
          zp23SpbUbnzCN4

          environment {ROOT = ' '}
          
          if (ROOT == ' ') {   
              echo "Null Root. Set it to empty"      
              ROOT = ''
          }
          

          vad vad added a comment - The current work around is set the variable to space then replace space with empty later in pipeline zp23SpbUbnzCN4 environment {ROOT =  ' ' } if  (ROOT ==  ' ' ) {    echo  "Null Root. Set it to empty"        ROOT = '' }

          Hi, I also stumbled painfully over this one

          imho this should be considered as bug, as I could not find anything in groovy references, which would indicate that an empty string could be treated as null.

          Even in the Jenkins-console assigning "" is perfectly fine, and it is not treated as null.

          Oracle hosted docs also pointing out the difference.

          But what I originally wanted to share. If you only want to use the variable in a `sh` step for example, you could use (if feasible) on single quotes to avoid variable substitution on groovy side, then an undefined variable is again empty (but also undefined, which could be the same non-differentiating issue again).

          br Michael

          Michael Musenbrock added a comment - Hi, I also stumbled painfully over this one imho this should be considered as bug, as I could not find anything in groovy references, which would indicate that an empty string could be treated as null. Even in the Jenkins-console assigning "" is perfectly fine, and it is not treated as null. Oracle hosted docs also pointing out the difference. But what I originally wanted to share. If you only want to use the variable in a `sh` step for example, you could use (if feasible) on single quotes to avoid variable substitution on groovy side, then an undefined variable is again empty (but also undefined, which could be the same non-differentiating issue again). br Michael

          Tim Black added a comment -

          Sigh. +1 This is obviously a bug. Only workaround I can see is to not use Jenkins environment variables. Sigh.

          Tim Black added a comment - Sigh. +1 This is obviously a bug. Only workaround I can see is to not use Jenkins environment variables. Sigh.

            Unassigned Unassigned
            jedavis Jason Davis
            Votes:
            26 Vote for this issue
            Watchers:
            26 Start watching this issue

              Created:
              Updated: