commit ca978d82dfd5478176db4ff6d3a01bb9daad80bb
Author: unknown <Jeremy@.(none)>
Date:   Tue Jun 14 22:53:33 2011 -0500

    Committer: Jeremy Van Haren
    
    Addressing [JENKINS-9968]

diff --git a/core/src/main/java/hudson/cli/BuildCommand.java b/core/src/main/java/hudson/cli/BuildCommand.java
index a214dd6..176834a 100644
--- a/core/src/main/java/hudson/cli/BuildCommand.java
+++ b/core/src/main/java/hudson/cli/BuildCommand.java
@@ -30,10 +30,12 @@ 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 org.kohsuke.args4j.Argument;
 import org.kohsuke.args4j.Option;
 
@@ -63,6 +65,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")
+    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 +94,12 @@ public class BuildCommand extends CLICommand {
             a = new ParametersAction(values);
         }
 
+        if (checkSCM) {
+            if (job.poll(TaskListener.NULL) == PollingResult.NO_CHANGES) {
+                return 0;
+            }
+        }
+
         Future<? extends AbstractBuild> f = job.scheduleBuild2(0, new CLICause(), a);
         if (!sync)  return 0;
 
@@ -104,7 +115,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"
         );
     }