package org.jenkinsci.plugins.p4.review; import hudson.EnvVars; import hudson.Extension; import hudson.matrix.MatrixRun; import hudson.model.Result; import hudson.model.Run; import hudson.model.TaskListener; import hudson.model.listeners.RunListener; import jenkins.model.Jenkins; import jenkins.model.JenkinsLocationConfiguration; import java.io.OutputStreamWriter; import java.net.HttpURLConnection; import java.net.URL; import java.util.logging.Logger; @Extension public class ReviewNotifier extends RunListener<Run> { private static Logger logger = Logger.getLogger(ReviewNotifier.class.getName()); @Override public void onCompleted(Run run, TaskListener listener) { if (run instanceof MatrixRun) { return; } try { EnvVars env = run.getEnvironment(listener); String fail = env.get(ReviewProp.FAIL.getProp()); String pass = env.get(ReviewProp.PASS.getProp()); Result result = run.getResult(); if (result == null) { logger.warning("Result is null!"); return; } Jenkins j = Jenkins.getInstance(); if (j == null) { logger.warning("Jenkins instance is null!"); return; } // only process valid URLs (this gets triggered for non Reviews too) String url = (result.equals(Result.SUCCESS)) ? pass : fail; if (url != null && !url.isEmpty()) { String rootUrl = j.getRootUrl(); if (rootUrl == null) { JenkinsLocationConfiguration globalConfig = new JenkinsLocationConfiguration(); rootUrl = (globalConfig.getUrl() == null) ? "unset" : globalConfig.getUrl(); } String path = run.getUrl(); postURL(url, rootUrl + path); } } catch (Exception e) { logger.warning("Unable to Notify Review"); e.printStackTrace(); } return; } private void postURL(String postUrl, String buildUrl) throws Exception { logger.info("ReviewNotifier: " + postUrl + " url=" + buildUrl); URL url = new URL(postUrl); HttpURLConnection http = (HttpURLConnection) url.openConnection(); http.setDoInput(true); http.setDoOutput(true); http.setUseCaches(false); http.setRequestMethod("POST"); http.connect(); OutputStreamWriter writer = new OutputStreamWriter(http.getOutputStream(), "UTF-8"); writer.write("url=" + buildUrl); writer.flush(); writer.close(); int response = http.getResponseCode(); logger.info("Response code: " + response); } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#11 | 24529 | Paul Allen |
Swarm Commit Event support, refactoring and test. JENKINS-52605 (Fix doc in 'Includes' help bubble for MultiBranch) JENKINS-52066 (Improve Swarm Commit and Branch Event support) |
||
#10 | 24488 | Paul Allen |
Min version Jenkins 2.60.3 Upgrade dependencies and move to Java 8. |
||
#9 | 22219 | Paul Allen |
Use JenkinsLocationConfiguration to fetch the URL If Jenkins getRootUrl() returns null try JenkinsLocationConfiguration. |
||
#8 | 19612 | Paul Allen | Polling fix, if no previous build. | ||
#7 | 19581 | Paul Allen | Minor fixes to satisfy FindBugs Analysis. | ||
#6 | 15557 | Paul Allen |
Simplification of ReviewNotifier Remove Apache HttpClient dependancy and separate setup environment step. Notification triggered onCompleted event, called after a build is completed. |
||
#5 | 11581 | Paul Allen | More compatible to use getUrl() method. | ||
#4 | 11154 | Paul Allen |
Block Swarm URL callback for Matrix children Allow parent to aggregate result for Swarm callback. JENKINS-25480 |
||
#3 | 11093 | Paul Allen | Trigger Swarm for pass/fail for multi builds. | ||
#2 | 10756 | Paul Allen |
[Missing file for change 10755] Separate name space for 'label' parameter. Perforce Review endpoint added `label`, `change`, `status`, `pass`, and `fail` parameter into the environment, which is a shared name space. This clashed with the default `label` matrix name and causing users issues. The change prefixes the review parameters with `p4.` on addition to the environment. |
||
#1 | 9690 | Paul Allen |
[Branching using p4-jenkins] Release 1.0.1 |
||
//guest/paul_allen/dev/p4-jenkins/p4-client/src/main/java/org/jenkinsci/plugins/p4/review/ReviewNotifier.java | |||||
#1 | 9672 | Paul Allen | Refactor name from 'p4_client' to 'p4'. | ||
//guest/paul_allen/dev/p4-jenkins/p4-client/src/main/java/org/jenkinsci/plugins/p4_client/review/ReviewNotifier.java | |||||
#7 | 8979 | Paul Allen | Build Url path by hand to avoid encoding error and added "UTF-8" to the UrlEncodedFormEntity method. | ||
#6 | 8971 | Paul Allen |
Attempt to fix rootUrl bug, but ended up tidying code. Turns out that you MUST set the Jenkins URL and click Save; even though the box has a default value it is not applied unless the configuration page is Applied/Saved. Manage Jenkins --> Configuration --> Jenkins Location: Jenkins URL |
||
#5 | 8858 | Paul Allen |
Ralf's URL link back to Jenkins. The Swarm review Action ReviewNotifier posts back a Jenkins URL for build job. (Requries a FQDN for Swarm-Jenkins config) |
||
#4 | 8762 | Paul Allen |
Console Ouptut logging for SCM build steps. - Removed SLF4J and used old style logger (matching Jenkins) - Set Client Host filed to null, Jenkins sometimes gives an IP address. - Test p4java setps in SCM tasks for success(true/false) |
||
#3 | 8725 | Paul Allen |
Minor fixes: - Improved tidy workspace method - Fix for template clients - After an unshelf revert -k files - Minor bug in CheckoutTask - Clear callback urls to prevet reuse |
||
#2 | 8715 | Paul Allen |
#review-8716 [Basic Swarm-Jenkins cycle DONE] Support Job's build notification and then POST's the pass/fail call-back URLs to Swarm. |
||
#1 | 8683 | Paul Allen | Simple Action plugin hooks for building reviews in a Jenkins Job. |