Skip to content
Permalink
Browse files

[JENKINS-23641] - Handle possible nulls if Git checkout fails

Signed-off-by: Oleg Nenashev <o.v.nenashev@gmail.com>
  • Loading branch information
oleg-nenashev committed Oct 12, 2014
1 parent 0f29b1d commit c4347f829f84fec909b7cfe1e6bc88b265a58e48
Showing with 11 additions and 3 deletions.
  1. +11 −3 src/main/java/com/cloudbees/jenkins/GitHubCommitNotifier.java
@@ -29,6 +29,7 @@
import java.io.IOException;

import static hudson.model.Result.*;
import hudson.plugins.git.Revision;

/**
* Create commit status notifications on the commits based on the outcome of the build.
@@ -50,8 +51,15 @@ public BuildStepMonitor getRequiredMonitorService() {
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {

BuildData buildData = build.getAction(BuildData.class);
String sha1 = ObjectId.toString(buildData.getLastBuiltRevision().getSha1());

if (buildData == null) {
throw new IOException("Cannot retrieve Git metadata for the build");
}
final Revision lastBuildRevision = buildData.getLastBuiltRevision();
final ObjectId sha1 = lastBuildRevision != null ? lastBuildRevision.getSha1() : null;
if (sha1 == null) { // Nowhere to report => fail the build
throw new IOException("Cannot determine sha1 of the commit. The status cannot be reported");
}

for (GitHubRepositoryName name : GitHubRepositoryNameContributor.parseAssociatedNames(build.getProject())) {
for (GHRepository repository : name.resolve()) {
GHCommitState state;
@@ -73,7 +81,7 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
}

listener.getLogger().println(Messages.GitHubCommitNotifier_SettingCommitStatus(repository.getUrl() + "/commit/" + sha1));
repository.createCommitStatus(sha1, state, build.getAbsoluteUrl(), msg);
repository.createCommitStatus(ObjectId.toString(sha1), state, build.getAbsoluteUrl(), msg);
}
}
return true;

0 comments on commit c4347f8

Please sign in to comment.
You can’t perform that action at this time.