cinderella

[unmaintained] simple CI engine
Log | Files | Refs | README | LICENSE

commit 9ab00b0d398da8376606dc36e4498ed7c9a29f81
parent 5f93e1ecbfe411bfcb58ab05bd539674bd3b016b
Author: Stefan Koch <programming@stefan-koch.name>
Date:   Mon, 23 Sep 2019 21:21:42 +0200

write command output to error mail

Diffstat:
Msrc/execution.rs | 20++++++++++++--------
Msrc/lib.rs | 4++--
2 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/src/execution.rs b/src/execution.rs @@ -9,8 +9,9 @@ use crate::pipeline; pub enum ExecutionResult { NoExecution, Success, - BuildError(String), - ExecutionError(String), + // failed command and its output + BuildError(String, String), + ExecutionError(String, String), } pub fn execute<W: Write>( @@ -33,10 +34,11 @@ pub fn execute<W: Write>( executed_at_least_one = true; let res = execute_pipeline(pipeline, &variables, stdout); - if let ExecutionResult::BuildError(msg) = res { - return ExecutionResult::BuildError(msg); - } else if let ExecutionResult::ExecutionError(msg) = res { - return ExecutionResult::ExecutionError(msg); + match res { + ExecutionResult::BuildError(_, _) | ExecutionResult::ExecutionError(_, _) => { + return res; + }, + _ => (), } } } @@ -67,14 +69,16 @@ fn execute_pipeline<W: Write>( .output(); let output = match output { Ok(output) => output, - Err(e) => return ExecutionResult::ExecutionError(e.to_string()), + Err(e) => return ExecutionResult::ExecutionError(cmd, e.to_string()), }; stdout.write_all(&output.stdout).unwrap(); + let outtext = String::from_utf8(output.stdout.iter().map(|&c| c as u8).collect()).unwrap(); if !output.status.success() { return ExecutionResult::BuildError( - String::from(format!("Pipeline failed in step: {}", cmd))); + String::from(format!("Pipeline failed in step: {}", cmd)), + outtext); } } diff --git a/src/lib.rs b/src/lib.rs @@ -83,9 +83,9 @@ pub fn run(repo_ptr: &RepoPointer) { let res = execution::execute(&pipelines, &variables, &mut io::stdout()); match res { - ExecutionResult::BuildError(msg) | ExecutionResult::ExecutionError(msg) => { + ExecutionResult::BuildError(msg, output) | ExecutionResult::ExecutionError(msg, output) => { let mailer = mail::build_mailer(&config.email); - mailer.send_mail(&format!("Build failed: {}", msg)); + mailer.send_mail(&format!("Build failed: {}\n{}", msg, output)); }, _ => (), }