Source:
public void onPost(String triggeredByUser) { final String pushBy = triggeredByUser; getDescriptor().queue.execute(new Runnable() { private boolean runPolling() { try { StreamTaskListener listener = new StreamTaskListener(getLogFile()); try { PrintStream logger = listener.getLogger(); long start = System.currentTimeMillis(); logger.println("Started on " + DateFormat.getDateTimeInstance().format(new Date())); boolean result = SCMTriggerItems.asSCMTriggerItem(job).poll(listener).hasChanges(); logger.println("Done. Took " + Util.getTimeSpanString(System.currentTimeMillis() - start)); if (result) { logger.println("Changes found"); } else { logger.println("No changes"); } return result; } catch (Error e) { e.printStackTrace(listener.error("Failed to record SCM polling")); LOGGER.log(Level.SEVERE,"Failed to record SCM polling",e); throw e; } catch (RuntimeException e) { e.printStackTrace(listener.error("Failed to record SCM polling")); LOGGER.log(Level.SEVERE,"Failed to record SCM polling",e); throw e; } finally { listener.close(); } } catch (IOException e) { LOGGER.log(Level.SEVERE,"Failed to record SCM polling",e); } return false; } public void run() { if (runPolling()) { String name = " #" + job.getNextBuildNumber(); GitHubPushCause cause; try { cause = new GitHubPushCause(getLogFile(), pushBy); } catch (IOException e) { LOGGER.log(Level.WARNING, "Failed to parse the polling log",e); cause = new GitHubPushCause(pushBy); } ParameterizedJobMixIn scheduler = new ParameterizedJobMixIn() {@Override protected Job asJob() {return job;}}; if (scheduler.scheduleBuild(cause)) { LOGGER.info("SCM changes detected in "+ job.getName()+". Triggering "+name); } else { LOGGER.info("SCM changes detected in "+ job.getName()+". Job is already in the queue"); } } } }); }

Target:
public void onPost(String triggeredByUser) { final String pushBy = triggeredByUser; getDescriptor().queue.execute(new Runnable() { private boolean runPolling() { try { StreamTaskListener listener = new StreamTaskListener(getLogFile()); try { PrintStream logger = listener.getLogger(); long start = System.currentTimeMillis(); logger.println("Started on " + DateFormat.getDateTimeInstance().format(new Date())); boolean result = SCMTriggerItems.asSCMTriggerItem(job).poll(listener).hasChanges(); logger.println("Done. Took " + Util.getTimeSpanString(System.currentTimeMillis() - start)); if (result) { logger.println("Changes found"); } else { logger.println("No changes"); } return result; } catch (Error e) { e.printStackTrace(listener.error("Failed to record SCM polling")); LOGGER.error("Failed to record SCM polling", e); throw e; } catch (RuntimeException e) { e.printStackTrace(listener.error("Failed to record SCM polling")); LOGGER.error("Failed to record SCM polling", e); throw e; } finally { listener.close(); } } catch (IOException e) { LOGGER.error("Failed to record SCM polling", e); } return false; } public void run() { if (runPolling()) { String name = " #" + job.getNextBuildNumber(); GitHubPushCause cause; try { cause = new GitHubPushCause(getLogFile(), pushBy); } catch (IOException e) { LOGGER.warn("Failed to parse the polling log", e); cause = new GitHubPushCause(pushBy); } ParameterizedJobMixIn scheduledJob = new ParameterizedJobMixIn() { @Override protected Job asJob() { return job; } }; if (scheduledJob.scheduleBuild(cause)) { LOGGER.info("SCM changes detected in " + job.getName() + ". Triggering " + name); } else { LOGGER.info("SCM changes detected in " + job.getName() + ". Job is already in the queue"); } } } }); }