package org.jenkinsci.plugins.p4_client.review; import hudson.Extension; import hudson.Launcher; import hudson.model.BuildListener; import hudson.model.Environment; import hudson.model.Result; import hudson.model.AbstractBuild; import hudson.model.Run; import hudson.model.Run.RunnerAbortedException; import hudson.model.listeners.RunListener; import java.io.IOException; import java.util.Map; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpPost; import org.apache.http.impl.client.DefaultHttpClient; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @Extension @SuppressWarnings("rawtypes") public class ReviewNotifier extends RunListener<Run> { private Logger logger = LoggerFactory.getLogger(ReviewNotifier.class); private String fail; private String pass; public ReviewNotifier() { super(Run.class); } @Override public Environment setUpEnvironment(AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException, RunnerAbortedException { @SuppressWarnings("unchecked") Map<String, String> map = build.getBuildVariables(); if (map != null) { if (map.containsKey("fail")) { fail = map.get("fail"); } if (map.containsKey("pass")) { pass = map.get("pass"); } } return new Environment() { }; } @Override public void onFinalized(Run r) { String url = fail; Result result = r.getResult(); if (result.equals(Result.SUCCESS)) { url = pass; } logger.info(result + " - " + url); try { postURL(url); } catch (Exception e) { e.printStackTrace(); } return; } private void postURL(String url) throws Exception { HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(url); HttpResponse response = client.execute(post); logger.info("Response code: " + response); } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#8 | 9672 | Paul Allen | Refactor name from 'p4_client' to 'p4'. | ||
#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. |