jenkins: post URL to test results
diff mbox

Message ID 20170203065206.17887-1-andrew.donnellan@au1.ibm.com
State Accepted
Headers show

Commit Message

Andrew Donnellan Feb. 3, 2017, 6:52 a.m. UTC
From: Russell Currey <ruscur@russell.cc>

Include a URL when posting test results. By default, link to the Jenkins
console output - however, this often has a lot of irrelevant garbage, so
also allow the configuration to specify the filename of a Jenkins artifact.

Signed-off-by: Russell Currey <ruscur@russell.cc>
Signed-off-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>

---

for information only, already merged

---
 examples/openpower.toml | 2 ++
 src/jenkins.rs          | 8 ++++++++
 src/main.rs             | 2 +-
 3 files changed, 11 insertions(+), 1 deletion(-)

Patch
diff mbox

diff --git a/examples/openpower.toml b/examples/openpower.toml
index d582576..c362d08 100644
--- a/examples/openpower.toml
+++ b/examples/openpower.toml
@@ -55,6 +55,7 @@  token = "33333333333333333333333333333333"
         job = "linux-build-manual"
         remote = "GIT_REPO_TO_USE"
         branch = "GIT_REF_TO_BUILD"
+        artifact = "snowpatch.txt"
         USER_EMAIL = "username"
         DEFCONFIG_TO_USE = "pseries_le_defconfig"
 
@@ -62,5 +63,6 @@  token = "33333333333333333333333333333333"
         job = "linux-build-manual"
         remote = "GIT_REPO_TO_USE"
         branch = "GIT_REF_TO_BUILD"
+        artifact = "snowpatch.txt"
         USER_EMAIL = "username"
         DEFCONFIG_TO_USE = "ppc64le_defconfig"
diff --git a/src/jenkins.rs b/src/jenkins.rs
index 0122a06..d2faad7 100644
--- a/src/jenkins.rs
+++ b/src/jenkins.rs
@@ -28,6 +28,7 @@  use std::io::Read;
 use std::time::Duration;
 use std::thread::sleep;
 use std::sync::Arc;
+use std::collections::BTreeMap;
 
 use hyper::Client;
 use hyper::client::{IntoUrl, RequestBuilder};
@@ -154,6 +155,13 @@  impl JenkinsBackend {
         }
     }
 
+    pub fn get_results_url(&self, build_url: &str, job: &BTreeMap<String, String>) -> String {
+        match job.get("artifact") {
+            Some(artifact) => format!("{}/artifact/{}", build_url, artifact),
+            None => format!("{}/consoleText/", build_url)
+        }
+    }
+
     pub fn wait_build(&self, build_url: &str) -> JenkinsBuildStatus {
         // TODO: Implement a timeout?
         while self.get_build_status(build_url) != JenkinsBuildStatus::Done {
diff --git a/src/main.rs b/src/main.rs
index c1bf0bf..e5ad03f 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -136,7 +136,7 @@  fn run_tests(settings: &Config, client: Arc<Client>, project: &Project, tag: &st
         results.push(TestResult {
             test_name: format!("{}/{}", branch_name.to_string(), job_name.to_string()),
             state: test_result,
-            url: None, // TODO: link to Jenkins job log
+            url: Some(jenkins.get_results_url(&build_url_real, job_params)),
             summary: Some("TODO: get this summary from Jenkins".to_string()),
         });
     }