@@ -59,10 +59,12 @@ public static void updateCommitStatus(
5959 return ;
6060 }
6161
62+ EnvVars environment = null ;
6263 if (gitLabBranchBuilds == null || gitLabBranchBuilds .isEmpty ()) {
6364 try {
64- if (!build .getEnvironment (listener ).isEmpty ()) {
65- gitLabBranchBuilds = retrieveGitlabProjectIds (build , build .getEnvironment (listener ));
65+ environment = build .getEnvironment (listener );
66+ if (!environment .isEmpty ()) {
67+ gitLabBranchBuilds = retrieveGitlabProjectIds (build , environment );
6668 }
6769 } catch (IOException | InterruptedException e ) {
6870 printf (listener , "Failed to get Gitlab Build list to update status: %s%n" , e .getMessage ());
@@ -96,7 +98,7 @@ public static void updateCommitStatus(
9698 gitLabBranchBuild .getProjectId (),
9799 gitLabBranchBuild .getRevisionHash (),
98100 state ,
99- getBuildBranchOrTag (build ),
101+ getBuildBranchOrTag (build , environment ),
100102 current_build_name ,
101103 buildUrl ,
102104 state .name ());
@@ -155,10 +157,10 @@ private static boolean existsCommit(GitLabClient client, String gitlabProjectId,
155157 }
156158 }
157159
158- private static String getBuildBranchOrTag (Run <?, ?> build ) {
160+ private static String getBuildBranchOrTag (Run <?, ?> build , EnvVars environment ) {
159161 GitLabWebHookCause cause = build .getCause (GitLabWebHookCause .class );
160162 if (cause == null ) {
161- return null ;
163+ return environment == null ? null : environment . get ( "BRANCH_NAME" , null ) ;
162164 }
163165 if (cause .getData ().getActionType () == CauseData .ActionType .TAG_PUSH ) {
164166 return StringUtils .removeStart (cause .getData ().getSourceBranch (), "refs/tags/" );
0 commit comments