EnvInject plugin reads a properties file each time I need to export a variable.
So I implemented the needed functionality using Groovy PostBuild plugin in the first post-build step which reads all needed variables from a properties file and exports them for the next post-build steps:
import hudson.model.*
def console = manager.listener.logger.&println
def props = new Properties()
new File("${manager.envVars['WORKSPACE']}/postbuild.props").withInputStream {
stream -> props.load(stream)
}
props.each{
key, value -> console("${key}:${value}")
def pa = new ParametersAction([
new StringParameterValue(key, value)
])
manager.build.addAction(pa)
}
And on each build step which needs to pass variables to post-build steps I do something like:
echo "hipchat_message=Server build succeded: <a href='https://$SERVER_NAME/'>$SERVER_NAME</a> (<a href='$BUILD_URL'>Job</a>)" > "$WORKSPACE/postbuild.props"