Prevent leaking environment information.

Changes the implementation of #1820 to prevent leaking other environment information into the build output.  For example after #1820 the development, test, and production environment configurations were available in the build output (even for production builds).

Now we only export the current environment and test (if testing is enabled).

This addresses the security concerns in #1750.