提交 7c606ae5 编写于 作者: J Jesse Glick

Merge branch 'fix-refused-build-cli-npe' of github.com:marco-miller/jenkins...

Merge branch 'fix-refused-build-cli-npe' of github.com:marco-miller/jenkins into marco-miller-fix-refused-build-cli-npe
......@@ -89,6 +89,8 @@ public class BuildCommand extends CLICommand {
@Option(name="-r") @Deprecated
public int retryCnt = 10;
protected static final String BUILD_SCHEDULING_REFUSED = "Build scheduling Refused by an extension, hence not in Queue";
protected int run() throws Exception {
job.checkPermission(Item.BUILD);
......@@ -141,6 +143,10 @@ public class BuildCommand extends CLICommand {
QueueTaskFuture<? extends AbstractBuild> f = job.scheduleBuild2(0, new CLICause(Jenkins.getAuthentication().getName()), a);
if (wait || sync || follow) {
if (f == null) {
stderr.println(BUILD_SCHEDULING_REFUSED);
return -1;
}
AbstractBuild b = f.waitForStart(); // wait for the start
stdout.println("Started "+b.getFullDisplayName());
......
......@@ -23,22 +23,27 @@
*/
package hudson.cli
import org.jvnet.hudson.test.JenkinsRule
import org.junit.Rule
import org.junit.Test
import org.apache.commons.io.output.TeeOutputStream
import static org.junit.Assert.*
import org.junit.Assume
import hudson.tasks.Shell
import hudson.util.OneShotEvent
import org.junit.Rule
import org.junit.Test
import org.jvnet.hudson.test.JenkinsRule
import org.jvnet.hudson.test.TestBuilder
import hudson.model.AbstractBuild
import hudson.model.FreeStyleProject;
import org.jvnet.hudson.test.TestExtension
import hudson.Launcher
import hudson.model.AbstractBuild
import hudson.model.Action
import hudson.model.BuildListener
import hudson.model.FreeStyleProject;
import hudson.model.ParametersAction
import hudson.model.ParametersDefinitionProperty
import hudson.model.Queue.QueueDecisionHandler
import hudson.model.Queue.Task;
import hudson.model.StringParameterDefinition
import hudson.model.ParametersAction
import org.apache.commons.io.output.TeeOutputStream
import hudson.tasks.Shell
import hudson.util.OneShotEvent
/**
* {@link BuildCommand} test.
......@@ -72,7 +77,6 @@ public class BuildCommandTest {
} finally {
cli.close();
}
}
/**
......@@ -89,7 +93,6 @@ public class BuildCommandTest {
} finally {
cli.close();
}
}
/**
......@@ -152,6 +155,26 @@ public class BuildCommandTest {
}
}
@Test void consoleOutputWhenBuildSchedulingRefused() {
Assume.assumeFalse("Started test0 #1", "https://jenkins.ci.cloudbees.com/job/core/job/jenkins_main_trunk/".equals(System.getenv("JOB_URL")))
def p = j.createFreeStyleProject()
def cli = new CLI(j.URL)
try {
def o = new ByteArrayOutputStream()
cli.execute(["build","-s","-v",p.name],System.in,System.out,new TeeOutputStream(System.err,o))
assertTrue(o.toString(), o.toString().contains(BuildCommand.BUILD_SCHEDULING_REFUSED))
} finally {
cli.close()
}
}
// <=>
@TestExtension("consoleOutputWhenBuildSchedulingRefused")
static class UnschedulingVetoer extends QueueDecisionHandler {
public boolean shouldSchedule(Task task, List<Action> actions) {
return false;
}
}
@Test void refuseToBuildDisabledProject() {
def project = j.createFreeStyleProject("the-project");
......@@ -180,7 +203,7 @@ public class BuildCommandTest {
def project = j.createFreeStyleProject("the-project");
project.addProperty(new ParametersDefinitionProperty([
new StringParameterDefinition("expr", null)
new StringParameterDefinition("expr", null)
]));
def invoker = new CLICommandInvoker(j, new BuildCommand());
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册