Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[Fix JENKINS-32519] Fix problem finding current revision
  • Loading branch information
Antonio Mansilla committed Jan 21, 2016
1 parent 880e29a commit 9a8ca27
Showing 1 changed file with 8 additions and 11 deletions.
Expand Up @@ -8,9 +8,8 @@
import hudson.model.AbstractProject;
import hudson.model.BuildListener;
import hudson.model.Result;
import hudson.plugins.git.GitChangeSet;
import hudson.plugins.git.GitChangeSetList;
import hudson.plugins.git.GitSCM;
import hudson.plugins.git.util.BuildData;
import hudson.scm.SCM;
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.BuildStepMonitor;
Expand Down Expand Up @@ -177,7 +176,6 @@ private BitbucketBuildStatusResource createBuildStatusResourceFromBuild(final Ab
throw new Exception("Bitbucket build notifier could not extract the repository name from the repository URL");
}

//
String userName = repoUrl.substring(0, repoUrl.indexOf("/" + repoName));
if (userName.indexOf("/") != -1) {
userName = userName.substring(userName.indexOf("/") + 1, userName.length());
Expand All @@ -186,17 +184,16 @@ private BitbucketBuildStatusResource createBuildStatusResourceFromBuild(final Ab
throw new Exception("Bitbucket build notifier could not extract the user name from the repository URL");
}

//
if (build.getChangeSets().size() <= 0) {
throw new Exception("No change set to send to Bitbucket!");
// find current revision
BuildData buildData = build.getAction(BuildData.class);
if(buildData == null || buildData.getLastBuiltRevision() == null) {
throw new Exception("Revision could not be found");
}

GitChangeSetList changeSets = (GitChangeSetList) build.getChangeSets().get(0);
List<GitChangeSet> gitChangeSet = changeSets.getLogs();
if (gitChangeSet.size() < 1) {
throw new Exception("No commits found on change set to send to Bitbucket!");
String commitId = buildData.getLastBuiltRevision().getSha1String();
if (commitId == null) {
throw new Exception("Commit ID could not be found!");
}
String commitId = gitChangeSet.get(gitChangeSet.size() - 1).getCommitId();

return new BitbucketBuildStatusResource(userName, repoName, commitId);
}
Expand Down

0 comments on commit 9a8ca27

Please sign in to comment.