@@ -1051,6 +1051,8 @@ public Revision invoke(File localWorkspace, VirtualChannel channel)
10511051 }
10521052 listener .getLogger ().println ("Commencing build of " + revToBuild );
10531053 environment .put (GIT_COMMIT , revToBuild .getSha1String ());
1054+ Branch branch = revToBuild .getBranches ().iterator ().next ();
1055+ environment .put (GIT_BRANCH , branch .getName ());
10541056
10551057 if (mergeOptions .doMerge () && !revToBuild .containsBranchName (mergeOptions .getRemoteBranchName ())) {
10561058 build .addAction (workingDirectory .act (new FileCallable <BuildData >() {
@@ -1237,13 +1239,16 @@ private void computeChangeLog(IGitAPI git, Revision revToBuild, BuildListener li
12371239
12381240 public void buildEnvVars (AbstractBuild <?, ?> build , java .util .Map <String , String > env ) {
12391241 super .buildEnvVars (build , env );
1240- String branch = getSingleBranch (build );
1241- if (branch != null ) {
1242- env .put (GIT_BRANCH , branch );
1243- }
1244- BuildData bd = fixNull (getBuildData (build , false ));
1245- if ((bd != null ) && (bd .getLastBuiltRevision () != null )) {
1246- String commit = bd .getLastBuiltRevision ().getSha1String ();
1242+ Revision rev = fixNull (getBuildData (build , false )).getLastBuiltRevision ();
1243+ String singleBranch = getSingleBranch (build );
1244+ if (singleBranch != null ){
1245+ env .put (GIT_BRANCH , singleBranch );
1246+ } else if (rev != null ) {
1247+ Branch branch = rev .getBranches ().iterator ().next ();
1248+ env .put (GIT_BRANCH , branch .getName ());
1249+ }
1250+ if (rev != null ) {
1251+ String commit = rev .getSha1String ();
12471252 if (commit != null ) {
12481253 env .put (GIT_COMMIT , commit );
12491254 }
0 commit comments