Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle NOT_BUILT and ABORTED as other results #400

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -150,56 +150,59 @@
continue;
}
for (QueueTaskFuture<AbstractBuild> future : futures.get(p)) {
if (future == null) {

Check warning on line 153 in src/main/java/hudson/plugins/parameterizedtrigger/TriggerBuilder.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 153 is only partially covered, one branch is missing
listener.getLogger()
.println("Skipping " + ModelHyperlinkNote.encodeTo(p)
+ ". The project was not triggered for some reason.");
continue;

Check warning on line 157 in src/main/java/hudson/plugins/parameterizedtrigger/TriggerBuilder.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 154-157 are not covered by tests
}

listener.getLogger()
.println("Waiting for the completion of "
+ HyperlinkNote.encodeTo('/' + p.getUrl(), p.getFullDisplayName()));
Run startedRun;
Result completedResult;
try {
if (future != null) {
listener.getLogger()
.println("Waiting for the completion of "
+ HyperlinkNote.encodeTo('/' + p.getUrl(), p.getFullDisplayName()));
Run startedRun;
try {
startedRun = future.waitForStart();
} catch (InterruptedException x) {
listener.getLogger()
.println("Build aborting: cancelling queued project "
+ HyperlinkNote.encodeTo(
'/' + p.getUrl(), p.getFullDisplayName()));
future.cancel(true);
throw x; // rethrow so that the triggering project get flagged as cancelled
}

listener.getLogger()
.println(HyperlinkNote.encodeTo(
'/' + startedRun.getUrl(), startedRun.getFullDisplayName())
+ " started.");

Run completedRun = future.get();
listener.getLogger()
.println(HyperlinkNote.encodeTo(
'/' + completedRun.getUrl(),
completedRun.getFullDisplayName())
+ " completed. Result was " + completedRun.getResult());
BuildInfoExporterAction.addBuildInfoExporterAction(
build,
completedRun.getParent().getFullName(),
completedRun.getNumber(),
completedRun.getResult());

if (buildStepResult
&& config.getBlock().mapBuildStepResult(completedRun.getResult())) {
Result r = config.getBlock().mapBuildResult(completedRun.getResult());
if (r != null) { // The blocking job is not a success
build.setResult(r);
}
} else {
buildStepResult = false;
}
} else {
listener.getLogger()
.println("Skipping " + ModelHyperlinkNote.encodeTo(p)
+ ". The project was not triggered by some reason.");
}
startedRun = future.waitForStart();
listener.getLogger()
.println(HyperlinkNote.encodeTo(
'/' + startedRun.getUrl(), startedRun.getFullDisplayName())
+ " started.");

Run completedRun = future.get();
completedResult = completedRun.getResult();
listener.getLogger()
.println(HyperlinkNote.encodeTo(
'/' + completedRun.getUrl(), completedRun.getFullDisplayName())
+ " completed. Result was " + completedResult);

BuildInfoExporterAction.addBuildInfoExporterAction(
build,
completedRun.getParent().getFullName(),
completedRun.getNumber(),
completedResult);

} catch (InterruptedException x) {
listener.getLogger()
.println("Build aborting: cancelling queued project "
+ HyperlinkNote.encodeTo('/' + p.getUrl(), p.getFullDisplayName()));
future.cancel(true);
throw x; // rethrow so that the triggering project get flagged as cancelled
} catch (CancellationException x) {
throw new AbortException(p.getFullDisplayName() + " aborted.");
listener.getLogger()
.println("Not built: " + p.getFullDisplayName()
+ " has been cancelled while waiting in the queue.");
completedResult = Result.NOT_BUILT;
}

if (buildStepResult && config.getBlock().mapBuildStepResult(completedResult)) {

Check warning on line 198 in src/main/java/hudson/plugins/parameterizedtrigger/TriggerBuilder.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 198 is only partially covered, 2 branches are missing

Result r = config.getBlock().mapBuildResult(completedResult);
if (r != null) { // The blocking job is not a success
build.setResult(r);
}
} else {
buildStepResult = false;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,39 @@ public void testCancelsDownstreamBuildWhenInterrupted() throws Exception {
assertEquals("No build left in queue", 0, r.jenkins.getQueue().countBuildableItems());
}

@Test
public void testCancelledFromBuildQueue() throws Exception {
r.jenkins.setNumExecutors(1); // the downstream-project would be in the build queue

FreeStyleProject triggerProject = r.createFreeStyleProject("upstream-project");
FreeStyleProject downstreamProject = r.createFreeStyleProject("downstream-project");

TriggerBuilder triggerBuilder = new TriggerBuilder(createTriggerConfig("downstream-project"));

triggerProject.getBuildersList().add(triggerBuilder);
QueueTaskFuture<FreeStyleBuild> parentBuild = triggerProject.scheduleBuild2(0);

parentBuild.waitForStart();
Thread.sleep(500);

assertEquals(
"Downstream project is in build queue", 1, r.jenkins.getQueue().countBuildableItems());

// Cancel the queued build
r.jenkins.getQueue().clear();
parentBuild.get();

assertLines(
triggerProject.getLastBuild(),
"Waiting for the completion of downstream-project",
"Not built: downstream-project has been cancelled while waiting in the queue.",
// The test class configures the BlockingBehaviour to never
// fail and that includes cancelled job.
"Finished: SUCCESS");
assertNull("No downstream build has been run", downstreamProject.getLastBuild());
assertEquals("No build left in queue", 0, r.jenkins.getQueue().countBuildableItems());
}

@Test
public void testConsoleOutputWithCounterParameters() throws Exception {
r.createFreeStyleProject("project1");
Expand Down