Skip to content
Permalink
Browse files

[FIXED JENKINS-21464] save current Build in BuildData before re-sched…

…uling job
  • Loading branch information...
ndeloof committed Sep 22, 2014
1 parent db14f9f commit cf964ea9474b1436dfcc7706ac62505ff93119dd
Showing with 29 additions and 29 deletions.
  1. +29 −29 src/main/java/hudson/plugins/git/GitSCM.java
@@ -814,7 +814,7 @@ public EnvVars getEnvironment() {
final TaskListener listener) throws IOException, InterruptedException {
PrintStream log = listener.getLogger();

Revision marked = null;
Collection<Revision> candidates = Collections.EMPTY_LIST;

// every MatrixRun should build the same marked commit ID
if (build instanceof MatrixRun) {
@@ -824,12 +824,12 @@ public EnvVars getEnvironment() {
if (parentBuildData != null) {
Build lastBuild = parentBuildData.lastBuild;
if (lastBuild!=null)
marked = lastBuild.getMarked();
candidates = Collections.singleton(lastBuild.getMarked());
}
}
}

if( marked == null ) {
if (candidates.isEmpty() ) {
// parameter forcing the commit ID to build
final RevisionParameterAction rpa = build.getAction(RevisionParameterAction.class);
if (rpa != null)
@@ -838,39 +838,40 @@ public EnvVars getEnvironment() {
final String singleBranch = environment.expand( getSingleBranch(environment) );

final BuildChooserContext context = new BuildChooserContextImpl(build.getParent(), build, environment);
Collection<Revision> candidates = getBuildChooser().getCandidateRevisions(
candidates = getBuildChooser().getCandidateRevisions(
false, singleBranch, git, listener, buildData, context);
}

if (candidates.size() == 0) {
// getBuildCandidates should make the last item the last build, so a re-build
// will build the last built thing.
throw new AbortException("Couldn't find any revision to build. Verify the repository and branch configuration for this job.");
}

if (candidates.size() > 1) {
log.println("Multiple candidate revisions");
Job<?, ?> job = build.getParent();
if (job instanceof AbstractProject) {
AbstractProject project = (AbstractProject) job;
if (!project.isDisabled()) {
log.println("Scheduling another build to catch up with " + project.getFullDisplayName());
if (!project.scheduleBuild(0, new SCMTrigger.SCMTriggerCause())) {
log.println("WARNING: multiple candidate revisions, but unable to schedule build of " + project.getFullDisplayName());
}
}
}

}

marked = candidates.iterator().next();
if (candidates.isEmpty()) {
// getBuildCandidates should make the last item the last build, so a re-build
// will build the last built thing.
throw new AbortException("Couldn't find any revision to build. Verify the repository and branch configuration for this job.");
}


Revision marked = candidates.iterator().next();
Revision rev = marked;
//Modify the revision based on extensions
for (GitSCMExtension ext : extensions) {
rev = ext.decorateRevisionToBuild(this,build,git,listener,rev);
}
return new Build(marked, rev, build.getNumber(), null);
Build revToBuild = new Build(marked, rev, build.getNumber(), null);
buildData.saveBuild(revToBuild);

if (candidates.size() > 1) {
log.println("Multiple candidate revisions");
Job<?, ?> job = build.getParent();
if (job instanceof AbstractProject) {
AbstractProject project = (AbstractProject) job;
if (!project.isDisabled()) {
log.println("Scheduling another build to catch up with " + project.getFullDisplayName());
if (!project.scheduleBuild(0, new SCMTrigger.SCMTriggerCause("This build was triggered by build "
+ build.getNumber() + " because more than one build candidate was found."))) {
log.println("WARNING: multiple candidate revisions, but unable to schedule build of " + project.getFullDisplayName());
}
}
}
}
return revToBuild;
}

/**
@@ -955,7 +956,6 @@ public void checkout(Run<?, ?> build, Launcher launcher, FilePath workspace, Tas
throw new IOException("Could not checkout " + revToBuild.revision.getSha1String(), e);
}

buildData.saveBuild(revToBuild);
build.addAction(new GitTagAction(build, workspace, buildData));

if (changelogFile != null) {

0 comments on commit cf964ea

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