Skip to content

Commit

Permalink
[FIXED JENKINS-19749] Add a -f option for following the build without…
Browse files Browse the repository at this point in the history
… passing interrupts through to the build
  • Loading branch information
stephenc committed Sep 25, 2013
1 parent de9816e commit 1f5673d
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions core/src/main/java/hudson/cli/BuildCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
import hudson.model.ParameterDefinition;
import hudson.Extension;
import hudson.AbortException;
import hudson.console.ModelHyperlinkNote;
import hudson.model.Item;
import hudson.model.Result;
import hudson.model.TaskListener;
import hudson.model.queue.QueueTaskFuture;
import hudson.scm.PollingResult.Change;
Expand All @@ -43,15 +43,13 @@
import org.kohsuke.args4j.Argument;
import org.kohsuke.args4j.Option;

import java.io.IOException;
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
import java.util.Map.Entry;
import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.util.concurrent.ExecutionException;

import jenkins.model.Jenkins;

Expand All @@ -70,7 +68,10 @@ public String getShortDescription() {
@Argument(metaVar="JOB",usage="Name of the job to build",required=true)
public AbstractProject<?,?> job;

@Option(name="-s",usage="Wait until the completion/abortion of the command")
@Option(name="-f", usage="Follow the build progress. Like -s only interrupts are not passed through to the build.")
public boolean follow = false;

@Option(name="-s",usage="Wait until the completion/abortion of the command. Interrupts are passed through to the build.")
public boolean sync = false;

@Option(name="-w",usage="Wait until the start of the command")
Expand Down Expand Up @@ -144,11 +145,11 @@ protected int run() throws Exception {

QueueTaskFuture<? extends AbstractBuild> f = job.scheduleBuild2(0, new CLICause(Jenkins.getAuthentication().getName()), a);

if (wait || sync) {
if (wait || sync || follow) {
AbstractBuild b = f.waitForStart(); // wait for the start
stdout.println("Started "+b.getFullDisplayName());

if (sync) {
if (sync || follow) {
try {
if (consoleOutput) {
// read output in a retry loop, by default try only once
Expand All @@ -174,9 +175,13 @@ protected int run() throws Exception {
stdout.println("Completed "+b.getFullDisplayName()+" : "+b.getResult());
return b.getResult().ordinal;
} catch (InterruptedException e) {
// if the CLI is aborted, try to abort the build as well
f.cancel(true);
throw e;
if (follow) {
return 125;
} else {
// if the CLI is aborted, try to abort the build as well
f.cancel(true);
throw e;
}
}
}
}
Expand All @@ -191,7 +196,12 @@ protected void printUsageSummary(PrintStream stderr) {
"Aside from general scripting use, this command can be\n" +
"used to invoke another job from within a build of one job.\n" +
"With the -s option, this command changes the exit code based on\n" +
"the outcome of the build (exit code 0 indicates a success.)\n" +
"the outcome of the build (exit code 0 indicates a success)\n" +
"and interrupting the command will interrupt the job.\n" +
"With the -f option, this command changes the exit code based on\n" +
"the outcome of the build (exit code 0 indicates a success)\n" +
"however, unlike -s, interrupting the command will not interrupt\n" +
"the job (exit code 125 indicates the command was interrupted)\n" +
"With the -c option, a build will only run if there has been\n" +
"an SCM change"
);
Expand Down

0 comments on commit 1f5673d

Please sign in to comment.