For some of our Jenkins jobs it happens that the builds irreversibly loose their injected environment variables when promoted. We see that the file injectedEnvVars.txt gets wiped empty, i.e. after triggering the promotion it has no contents anymore.
Unfortunately, we have no clues what causes this issue. We do not get any hints from the Jenkins log. And we have other jobs with promotions where this does not happen.
For the jobs where it happens the only common characteristic is that they reside in a folder. (Maybe this does not mean anything, but we never saw this issue happening for jobs not stored in a folder.) Update 2017-08-28: Today, I also saw this behaviour for a job not residing in a folder.
Loosing the variables does not happen during the build steps of the promotion but immediately after starting the promotion, so it does not seem to be related to the actual contents of the promotion. When "debugging" this issue by removing promotion build contents step by step we finally ended up with the promotion not containing any build steps anymore but the contents of injectedEnvVars.txt were still deleted. (So it really looks like this issue has nothing to do with the build steps of the promotion, but with promotion itself.)
That's all I can say – I am really sorry for not having more infomation about this.
Note: We use promotions for various scenarios and in some we need to access the environment variables of a build. Here is an example: We have an artefact build job and after the artefacts have been tested successfully (by other Jenkins jobs) we have a promotion for packaging the artefacts into an installer (the promotion triggers another Jenkins job that does the packaging). This packaging job usually would use a groovy script for accessing the environment variables of the original artefact build job (collecting information like version numbers etc). This is how we realised that environement variables have been deleted, since the packaging job was not able to retrieve the environment variables anymore. As a workaround we now create and archive a properties file in the artefact build job which is later copied and injected by the packing job.