Skip to content

Commit

Permalink
[FIXED JENKINS-23179] git pre-merge fails with matrix project
Browse files Browse the repository at this point in the history
  • Loading branch information
galbramc committed Jun 9, 2014
1 parent 5bdffc3 commit 288332c
Showing 1 changed file with 34 additions and 28 deletions.
62 changes: 34 additions & 28 deletions src/main/java/hudson/plugins/git/GitSCM.java
Expand Up @@ -770,48 +770,54 @@ public EnvVars getEnvironment() {
final BuildListener listener) throws IOException, InterruptedException {
PrintStream log = listener.getLogger();

// every MatrixRun should build the exact same commit ID
Revision marked = null;

// every MatrixRun should build the same marked commit ID
if (build instanceof MatrixRun) {
MatrixBuild parentBuild = ((MatrixRun) build).getParentBuild();
if (parentBuild != null) {
BuildData parentBuildData = getBuildData(parentBuild);
if (parentBuildData != null) {
Build lastBuild = parentBuildData.lastBuild;
if (lastBuild!=null)
return lastBuild;
marked = lastBuild.getMarked();
}
}
}

// parameter forcing the commit ID to build
final RevisionParameterAction rpa = build.getAction(RevisionParameterAction.class);
if (rpa != null)
return new Build(rpa.toRevision(git), build.getNumber(), null);

final String singleBranch = environment.expand( getSingleBranch(environment) );

final BuildChooserContext context = new BuildChooserContextImpl(build.getProject(), build, environment);
Collection<Revision> 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");
AbstractProject<?, ?> project = build.getProject();
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());
if( marked == null ) {
// parameter forcing the commit ID to build
final RevisionParameterAction rpa = build.getAction(RevisionParameterAction.class);
if (rpa != null)
return new Build(rpa.toRevision(git), build.getNumber(), null);

final String singleBranch = environment.expand( getSingleBranch(environment) );

final BuildChooserContext context = new BuildChooserContextImpl(build.getProject(), build, environment);
Collection<Revision> 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");
AbstractProject<?, ?> project = build.getProject();
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();
}
Revision rev = candidates.iterator().next();
Revision marked = rev;

Revision rev = marked;
//Modify the revision based on extensions
for (GitSCMExtension ext : extensions) {
rev = ext.decorateRevisionToBuild(this,build,git,listener,rev);
}
Expand Down

0 comments on commit 288332c

Please sign in to comment.