Skip to content
Permalink
Browse files
[FIXED JENKINS-9968] added an option to do polling before a build.
  • Loading branch information
kohsuke committed Aug 10, 2011
1 parent b375889 commit 259477a13a6c6cf1223739b88dd72c2a4f4e0392
@@ -77,6 +77,9 @@
(<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.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 String getShortDescription() {
@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 @@ protected int run() throws Exception {
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 @@ 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" +
"With the -c option, a build will only run if there has been\n" +
"an SCM change"
);
}

@@ -51,8 +51,11 @@
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 String call() throws IOException {
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.
*/

0 comments on commit 259477a

Please sign in to comment.