I do not know how to do what you ask but I can tell you how I solved the same problem:
In the job that has the promotion, at the end of the build I execute
echo $GIT_BRANCH > git_branch
and I archive git_branch
as a build artifact.
When a build of this job gets promoted, the promotion process triggers another job.
In this other job I use the Copy Artifact build step to get the file git_branch
from the promoted job. In "Which build" I configure "Specified by permalink" and as Permalink "Latest promotion:(name of promotion)"
The added benefit of this approach is that whatever actions I want to take, I can do them in a separate workspace of a separate job. As you may know, the promotion runs asynchronously and uses the workspace of the promoted job, so there is no guarantee the workspace exists or what the contents of the workspace are. Doing anything there might even conflict with another build currently running. It is much safer to do promotion-related actions in the context of another job.