Skip to content

Commit

Permalink
Switch to ignore post-commit hook in SCM polling triggers [FIXED JENK…
Browse files Browse the repository at this point in the history
…INS-6846]
  • Loading branch information
kutzi committed Nov 24, 2012
1 parent b546d6c commit 2de66bb
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/main/java/hudson/scm/SubversionRepositoryStatus.java
Expand Up @@ -14,6 +14,8 @@

import java.io.BufferedReader;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -63,6 +65,7 @@ public List<AbstractProject> getAllJobs() {
return Hudson.getInstance().getAllItems(AbstractProject.class);
}
};
private static Method IS_IGNORE_POST_COMMIT_HOOKS_METHOD;

// for tests
void setJobProvider(JobProvider jobProvider) {
Expand Down Expand Up @@ -125,7 +128,7 @@ public void doNotifyCommit(StaplerRequest req, StaplerResponse rsp) throws Servl
if (scm instanceof SubversionSCM) scmFound = true; else continue;

SCMTrigger trigger = p.getTrigger(SCMTrigger.class);
if (trigger!=null) triggerFound = true; else continue;
if (trigger!=null && !doesIgnorePostCommitHooks(trigger)) triggerFound = true; else continue;

SubversionSCM sscm = (SubversionSCM) scm;

Expand Down Expand Up @@ -178,12 +181,32 @@ public void doNotifyCommit(StaplerRequest req, StaplerResponse rsp) throws Servl
}

if (!scmFound) LOGGER.warning("No subversion jobs found");
else if (!triggerFound) LOGGER.warning("No subversion jobs using SCM polling");
else if (!triggerFound) LOGGER.warning("No subversion jobs using SCM polling or all jobs using SCM polling are ignoring post-commit hooks");
else if (!uuidFound) LOGGER.warning("No subversion jobs using repository: " + uuid);
else if (!pathFound) LOGGER.fine("No jobs found matching the modified files");

rsp.setStatus(SC_OK);
}

private boolean doesIgnorePostCommitHooks(SCMTrigger trigger) {
if (IS_IGNORE_POST_COMMIT_HOOKS_METHOD == null)
return false;

try {
return (Boolean)IS_IGNORE_POST_COMMIT_HOOKS_METHOD.invoke(trigger, (Object[])null);
} catch (Exception e) {
LOGGER.log(WARNING,"Failure when calling isIgnorePostCommitHooks",e);
return false;
}
}

static {
try {
IS_IGNORE_POST_COMMIT_HOOKS_METHOD = SCMTrigger.class.getMethod("isIgnorePostCommitHooks", (Class[])null);
} catch (Exception e) {
// we're running in an older Jenkins version which doesn't have this method
}
}

private static final Logger LOGGER = Logger.getLogger(SubversionRepositoryStatus.class.getName());
}

0 comments on commit 2de66bb

Please sign in to comment.