package org.jenkinsci.plugins.p4.review; import hudson.Extension; import hudson.Launcher; import hudson.matrix.MatrixRun; 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.ArrayList; import java.util.Map; import java.util.logging.Logger; import jenkins.model.Jenkins; import org.apache.http.HttpResponse; import org.apache.http.NameValuePair; import org.apache.http.client.HttpClient; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.HttpPost; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.message.BasicNameValuePair; @Extension @SuppressWarnings("rawtypes") public class ReviewNotifier extends RunListener<Run> { private static Logger logger = Logger.getLogger(ReviewNotifier.class .getName()); private String rootUrl = Jenkins.getInstance().getRootUrl(); 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 { // Ensure Urls are reset from previous build fail = null; pass = null; @SuppressWarnings("unchecked") Map<String, String> map = build.getBuildVariables(); if (map != null) { if (map.containsKey(ReviewProp.FAIL.getProp())) { fail = map.get(ReviewProp.FAIL.getProp()); } if (map.containsKey(ReviewProp.PASS.getProp())) { pass = map.get(ReviewProp.PASS.getProp()); } } return new Environment() { }; } @Override public void onFinalized(Run r) { if (r instanceof MatrixRun) { return; } String url = fail; Result result = r.getResult(); if (result.equals(Result.SUCCESS)) { url = pass; } try { if (url != null && !url.isEmpty()) { if (rootUrl == null) { postURL(url, null); } else { String name = r.getParent().getName(); int id = r.getNumber(); String path = "job/" + name + "/" + id + "/"; postURL(url, rootUrl + path); } } } catch (Exception e) { e.printStackTrace(); } return; } private void postURL(String url, String buildUrl) throws Exception { HttpClient client = HttpClientBuilder.create().build(); HttpPost post = new HttpPost(url); if (buildUrl != null) { ArrayList<NameValuePair> postParameters; postParameters = new ArrayList<NameValuePair>(); postParameters.add(new BasicNameValuePair("url", buildUrl)); post.setEntity(new UrlEncodedFormEntity(postParameters, "UTF-8")); } HttpResponse response = client.execute(post); logger.info("Response code: " + response); } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#3 | 11337 | Paul Allen | Merge down latest changes from MAIN | ||
#2 | 11107 | Paul Allen | Merging using p4-jenkins | ||
#1 | 11053 | Paul Allen | Branching using p4-jenkins | ||
//guest/perforce_software/p4jenkins/main/src/main/java/org/jenkinsci/plugins/p4/review/ReviewNotifier.java | |||||
#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. |