Skip to content

Commit

Permalink
[JENKINS-45729] Move printCommitMessageToLog after checkout, ignore e…
Browse files Browse the repository at this point in the history
…xceptions

JENKINS-45729 shows that there are cases where the expected commit is not
yet available to be printed or some other issue is causing an exception.

Printing the commit message of the last commit to the log file is a
diagnostic aid, not critical to success of the build.  An exception in
a diagnostic should not break the build.

I'm unable to duplicate JENKINS-45729 in any consistent way.  I have
seen the reported exception at least once, but the project with that
exception stopped showing that exception.
  • Loading branch information
MarkEWaite committed Sep 29, 2017
1 parent fe5a3f4 commit c1ac701
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/main/java/hudson/plugins/git/GitSCM.java
Expand Up @@ -1156,8 +1156,6 @@ public void checkout(Run<?, ?> build, Launcher launcher, FilePath workspace, Tas

listener.getLogger().println("Checking out " + revToBuild.revision);

printCommitMessageToLog(listener, git, revToBuild);

CheckoutCommand checkoutCommand = git.checkout().branch(localBranchName).ref(revToBuild.revision.getSha1String()).deleteBranchIfExist(true);
for (GitSCMExtension ext : this.getExtensions()) {
ext.decorateCheckoutCommand(this, build, git, listener, checkoutCommand);
Expand All @@ -1170,6 +1168,13 @@ public void checkout(Run<?, ?> build, Launcher launcher, FilePath workspace, Tas
throw new IOException("Could not checkout " + revToBuild.revision.getSha1String(), e);
}

// Needs to be after the checkout so that revToBuild is in the workspace
try {
printCommitMessageToLog(listener, git, revToBuild);
} catch (GitException ge) {
listener.getLogger().println("Exception logging commit message for " + revToBuild + ": " + ge.getMessage());
}

// Don't add the tag and changelog if we've already processed this BuildData before.
if (!buildDataAlreadyPresent) {
if (build.getActions(AbstractScmTagAction.class).isEmpty()) {
Expand Down

0 comments on commit c1ac701

Please sign in to comment.