public void doIndex(StaplerRequest req) throws IOException { String payload = IOUtils.toString(req.getReader()); LOGGER.fine("Full details of the POST was " + payload); JSONObject o = JSONObject.fromObject(payload); String repoUrl = o.getString("repository_ssl_path"); LOGGER.info("Received POST for " + repoUrl); // run in high privilege to see all the projects anonymous users don't see. // this is safe because when we actually schedule a build, it's a build that can // happen at some random time anyway. // TODO replace with ACL.impersonate as LTS is > 1.461 Authentication old = SecurityContextHolder.getContext().getAuthentication(); SecurityContextHolder.getContext().setAuthentication(ACL.SYSTEM); try { for (AbstractProject<?, ?> job : Jenkins.getInstance().getAllItems(AbstractProject.class)) { boolean found = false; SCM scm = job.getScm(); if (scm instanceof SubversionSCM) { found = hasRepository(repoUrl, (SubversionSCM) scm); } else if (scm instanceof GitSCM) { found = hasRepository(repoUrl, (GitSCM) scm); } else if (scm instanceof MercurialSCM) { found = hasRepository(repoUrl, (MercurialSCM) scm); } if (found) { LOGGER.info(job.getFullDisplayName() + " triggered by web hook."); job.scheduleBuild(new WebHookCause()); } LOGGER.fine( "Skipped " + job.getFullDisplayName() + " because it doesn't have a matching repository."); } } finally { SecurityContextHolder.getContext().setAuthentication(old); } }