Skip to content

Commit eaf0d82

Browse files
authored
Add additional debug logging to onNotifyCommit (#3929)
1 parent a43688b commit eaf0d82

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

src/main/java/hudson/plugins/git/GitStatus.java

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ public static class JenkinsAbstractProjectListener extends Listener {
360360
*/
361361
@Override
362362
public List<ResponseContributor> onNotifyCommit(String origin, URIish uri, String sha1, List<ParameterValue> buildParameters, String... branches) {
363+
long startMs = System.currentTimeMillis();
363364
sha1 = cleanupSha1(sha1);
364365
if (LOGGER.isLoggable(Level.FINE)) {
365366
LOGGER.log(Level.FINE, "Received notification from {0} for uri = {1} ; sha1 = {2} ; branches = {3}",
@@ -397,14 +398,30 @@ public List<ResponseContributor> onNotifyCommit(String origin, URIish uri, Strin
397398
branchMatches = false;
398399
URIish matchedURL = null;
399400
for (URIish remoteURL : repository.getURIs()) {
401+
if (LOGGER.isLoggable(Level.FINEST)) {
402+
LOGGER.log(Level.FINEST, "Comparing notified uri {0} against repository uri {1} in project {2}", new Object[]{uri, remoteURL, project.getFullDisplayName()});
403+
}
400404
if (looselyMatches(uri, remoteURL)) {
405+
if (LOGGER.isLoggable(Level.FINER)) {
406+
LOGGER.log(Level.FINER, "Repository uri {0} matches notified uri {1} in project {2}", new Object[]{remoteURL, uri, project.getFullDisplayName()});
407+
}
401408
repositoryMatches = true;
402409
matchedURL = remoteURL;
403410
break;
404411
}
405412
}
406413

407-
if (!repositoryMatches || git.getExtensions().get(IgnoreNotifyCommit.class)!=null) {
414+
if (!repositoryMatches) {
415+
if (LOGGER.isLoggable(Level.FINER)) {
416+
LOGGER.log(Level.FINER, "No matching repository uri for notified uri {0} in project {1}", new Object[]{uri, project.getFullDisplayName()});
417+
}
418+
continue;
419+
}
420+
421+
if (git.getExtensions().get(IgnoreNotifyCommit.class)!=null) {
422+
if (LOGGER.isLoggable(Level.FINER)) {
423+
LOGGER.log(Level.FINER, "Ignoring notified uri {0} match in project {1} due to ignore notify commit setting", new Object[]{uri, project.getFullDisplayName()});
424+
}
408425
continue;
409426
}
410427

@@ -422,6 +439,9 @@ public List<ResponseContributor> onNotifyCommit(String origin, URIish uri, Strin
422439
branchFound = true;
423440
} else {
424441
OUT: for (BranchSpec branchSpec : git.getBranches()) {
442+
if (LOGGER.isLoggable(Level.FINEST)) {
443+
LOGGER.log(Level.FINEST, "Comparing modified branches {0} against branch {1} in project {2}", new Object[]{Arrays.toString(branches), branchSpec.getName(), project.getFullDisplayName()});
444+
}
425445
if (branchSpec.getName().contains("$")) {
426446
// If the branchspec is parametrized, always run the polling
427447
if (LOGGER.isLoggable(Level.FINE)) {
@@ -442,7 +462,12 @@ public List<ResponseContributor> onNotifyCommit(String origin, URIish uri, Strin
442462
}
443463
}
444464
}
445-
if (!branchFound) continue;
465+
if (!branchFound) {
466+
if (LOGGER.isLoggable(Level.FINER)) {
467+
LOGGER.log(Level.FINER, "No matching branch spec for modified branches {0} in project {1}", new Object[]{Arrays.toString(branches), project.getFullDisplayName()});
468+
}
469+
continue;
470+
}
446471
urlFound = true;
447472
if (!(project instanceof ParameterizedJobMixIn.ParameterizedJob<?,?> job && job.isDisabled())) {
448473
//JENKINS-30178 Add default parameters defined in the job
@@ -499,6 +524,12 @@ public List<ResponseContributor> onNotifyCommit(String origin, URIish uri, Strin
499524
}
500525

501526
lastStaticBuildParameters = allBuildParameters;
527+
528+
if (LOGGER.isLoggable(Level.FINER)) {
529+
LOGGER.log(Level.FINER, "Processed notification from {0} for uri = {1} ; sha1 = {2} ; branches = {3} in {4} ms",
530+
new Object[]{StringUtils.defaultIfBlank(origin, "?"), uri, sha1, Arrays.toString(branches), System.currentTimeMillis() - startMs});
531+
}
532+
502533
return result;
503534
}
504535
}

0 commit comments

Comments
 (0)