Environment variables with empty values are not passed to process Jenkins exec

Environment variables with empty values are not passed to process Jenkins exec.

Here’s how to reproduce:

  1. Launch jenkins with environment variables
    • VAR=value VAR_EMPTY= java -jar jenkins.war
  2. Setup a job with execute shell step
    • shell script simply runs env command
  3. Trigger the job
  4. I can find VAR=value in the console output but can’t find VAR_EMPTY

I expect VAR_EMPTY= in the console output.

Environment variables with empty values get removed in EnvVars.

I’m not sure this is an intended design, but I’d like Jenkins to pass environment variables to jobs as is.
Some applications distinguish “environment variable with empty value” and “environment variable missing”.

Jenkins setup:

Jenkins: 2.426
OS: Mac OS X - 13.4.1
Java: - Homebrew (OpenJDK 64-Bit Server VM)

The code has behaved that way since 2007 (per the git history). Considering the compatibility statement in the Jenkins governance page, I would be truly surprised if that behavior would be changed. The compatibility section says:

We recognize that users expect their existing data, accumulated under past versions (including Hudson up to 1.395) to continue working under future versions of Jenkins. This includes jobs configurations, build records, and plugin binaries that they are using. The Jenkins project places high value on maintaining this compatibility, and will be very careful in removing functionality.

To enable the above goal, we also recognize that plugin developers expect APIs and other code that they depend on to remain available in future versions of Jenkins. This is not to say we don’t ever remove anything, but we do it very carefully.

Because one plugin can depend on another, we expect the same principle from plugins that many other plugins depend on.