jenkins: get build result
diff mbox

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

Commit Message

Andrew Donnellan Feb. 3, 2017, 6:39 a.m. UTC
When a build completes, get the result (success, failure or unstable) from
Jenkins, and use it to update Patchwork.

Closes: #14 ("Submit Jenkins test results to patchwork")
Signed-off-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>

---

for information only, already merged

---
 src/jenkins.rs | 15 +++++++++++++++
 src/main.rs    |  3 ++-
 2 files changed, 17 insertions(+), 1 deletion(-)

Patch
diff mbox

diff --git a/src/jenkins.rs b/src/jenkins.rs
index 1c63e75..0122a06 100644
--- a/src/jenkins.rs
+++ b/src/jenkins.rs
@@ -34,6 +34,8 @@  use hyper::client::{IntoUrl, RequestBuilder};
 use hyper::header::{Headers, Basic, Authorization, Location};
 use rustc_serialize::json::Json;
 
+use patchwork::TestState;
+
 // Constants
 const JENKINS_POLLING_INTERVAL: u64 = 5000; // Polling interval in milliseconds
 
@@ -139,6 +141,19 @@  impl JenkinsBackend {
         }
     }
 
+    pub fn get_build_result(&self, build_url: &str) -> Option<TestState> {
+        match self.get_api_json_object(build_url).get("result").unwrap()
+            .as_string() {
+            None => None,
+            Some(result) => match result { // TODO: Improve this...
+                "SUCCESS" => Some(TestState::success),
+                "FAILURE" => Some(TestState::failure),
+                "UNSTABLE" => Some(TestState::warning),
+                _ => Some(TestState::pending),
+            },
+        }
+    }
+
     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 9909243..c1bf0bf 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -131,10 +131,11 @@  fn run_tests(settings: &Config, client: Arc<Client>, project: &Project, tag: &st
         }
         debug!("Build URL: {}", build_url_real);
         jenkins.wait_build(&build_url_real);
+        let test_result = jenkins.get_build_result(&build_url_real).unwrap();
         info!("Jenkins job for {}/{} complete.", branch_name, job_name);
         results.push(TestResult {
             test_name: format!("{}/{}", branch_name.to_string(), job_name.to_string()),
-            state: TestState::success,
+            state: test_result,
             url: None, // TODO: link to Jenkins job log
             summary: Some("TODO: get this summary from Jenkins".to_string()),
         });