提交 259477a1 编写于 作者: K Kohsuke Kawaguchi

[FIXED JENKINS-9968] added an option to do polling before a build.

上级 b3758892
......@@ -77,6 +77,9 @@ Upcoming changes</a>
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-10414">issue 10414</a>)
<li class=rfe>
Added a dignosis CLI command to report the current granted authorities.
<li class=rfe>
Added an option in CLI build command to check for SCM changes before carrying out a build
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-9968">issue 9968</a>)
<li class=rfe>
If CLI fails to connect via a JNLP Slave port, fall back to HTTP full-duplex.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-10611">issue 10611</a>)
......
......@@ -30,13 +30,17 @@ import hudson.model.ParametersAction;
import hudson.model.ParameterValue;
import hudson.model.ParametersDefinitionProperty;
import hudson.model.ParameterDefinition;
import hudson.model.TaskListener;
import hudson.Extension;
import hudson.AbortException;
import hudson.model.Item;
import hudson.util.EditDistance;
import hudson.scm.PollingResult;
import hudson.util.StreamTaskListener;
import org.kohsuke.args4j.Argument;
import org.kohsuke.args4j.Option;
import java.nio.charset.Charset;
import java.util.concurrent.Future;
import java.util.Map;
import java.util.HashMap;
......@@ -63,6 +67,9 @@ public class BuildCommand extends CLICommand {
@Option(name="-s",usage="Wait until the completion/abortion of the command")
public boolean sync = false;
@Option(name="-c",usage="Check for SCM changes before starting the build, and if there's no change, exit without doing a build")
public boolean checkSCM = false;
@Option(name="-p",usage="Specify the build parameters in the key=value format.")
public Map<String,String> parameters = new HashMap<String, String>();
......@@ -89,6 +96,12 @@ public class BuildCommand extends CLICommand {
a = new ParametersAction(values);
}
if (checkSCM) {
if (job.poll(new StreamTaskListener(stdout, getClientCharset())) == PollingResult.NO_CHANGES) {
return 0;
}
}
Future<? extends AbstractBuild> f = job.scheduleBuild2(0, new CLICause(), a);
if (!sync) return 0;
......@@ -104,7 +117,9 @@ public class BuildCommand extends CLICommand {
"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" +
"With the -c option, a build will only run if there has been\n" +
"an SCM change"
);
}
......
......@@ -51,8 +51,11 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.lang.reflect.Type;
import java.nio.charset.Charset;
import java.nio.charset.UnsupportedCharsetException;
import java.util.List;
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
......@@ -303,6 +306,24 @@ public abstract class CLICommand implements ExtensionPoint, Cloneable {
private static final long serialVersionUID = 1L;
}
protected Charset getClientCharset() throws IOException, InterruptedException {
String charsetName = channel.call(new GetCharset());
try {
return Charset.forName(charsetName);
} catch (UnsupportedCharsetException e) {
LOGGER.log(Level.FINE,"Server doesn't have charset "+charsetName);
return Charset.defaultCharset();
}
}
private static final class GetCharset implements Callable<String, IOException> {
public String call() throws IOException {
return Charset.defaultCharset().name();
}
private static final long serialVersionUID = 1L;
}
/**
* Convenience method for subtypes to obtain environment variables of the client.
*/
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册