EnvInject plugin variables not getting injected from properties file in Jenkins build step

Today I had a bit of a struggle with the Jenkins EnvInject Plugin while trying to inject custom variables from a properties file into my MSBuild step. Everything that I added to the Properties Content field was successfully injected, and looking at the log, the EnvInject reported successfully injecting my file envVars.properties variables as well.

Jenkins EnvInject build step showing injection of variables from a properties file.

I used PowerShell to retrieve the current Git branch and echoed it into the envVars.properties file shown in the image above, which also turned out to be the culprit.

# $currentBranch set elsewhere.
echo CURRENT_GIT_BRANCH=$currentBranch > envVars.properties

All this gave me was an error about EnvInject having problems with the Byte Order Mark (BOM). Using a without-BOM encoding causes EnvInject to report success, but nothing gets injected.

The problem is the encoding of the properties file. It has to be encoded as ISO-8859-1 (Latin-1, with non-Latin-1 characters entered using Unicode escape characters).

# $currentBranch set elsewhere.
echo CURRENT_GIT_BRANCH=$currentBranch | Set-Content -Encoding ASCII -Path ".\envVars.properties"

So, generating the envVars.properties file in PowerShell using ASCII encoding, as above, sorts the issue.