Hydra/23: added some X-headers with meta info in email notifications, added more descriptive status

This commit is contained in:
Rob Vermaas 2010-04-26 14:36:56 +00:00
parent 1d0598272e
commit 2bfddaf4ae
2 changed files with 33 additions and 14 deletions

View file

@ -15,6 +15,7 @@ use Text::Table;
use POSIX qw(strftime); use POSIX qw(strftime);
use Net::Twitter::Lite; use Net::Twitter::Lite;
use Data::Dump qw(dump); use Data::Dump qw(dump);
use Switch;
STDOUT->autoflush(); STDOUT->autoflush();
@ -62,6 +63,20 @@ sub sendTwitterNotification {
warn "$@\n" if $@; warn "$@\n" if $@;
} }
sub statusDescription {
my ($buildstatus) = @_;
my $status = "Unknown failure";
switch ($buildstatus) {
case 0 { $status = "Success"; }
case 1 { $status = "Failed with non-zero exit code"; }
case 2 { $status = "Dependency failed"; }
case 4 { $status = "Cancelled"; }
}
return $status;
}
sub sendEmailNotification { sub sendEmailNotification {
my ($build) = @_; my ($build) = @_;
@ -94,17 +109,11 @@ sub sendEmailNotification {
my $jobName = $build->project->name . ":" . $build->jobset->name . ":" . $build->job->name; my $jobName = $build->project->name . ":" . $build->jobset->name . ":" . $build->job->name;
my $status = $build->resultInfo->buildstatus == 0 ? "SUCCEEDED" : "FAILED"; my $status = statusDescription($build->resultInfo->buildstatus);
my $statusMsg;
if(defined $prevBuild) {
my $prevStatus = $prevBuild->resultInfo->buildstatus == 0 ? "SUCCEEDED" : "FAILED";
$statusMsg = "changed from $prevStatus to $status";
} else {
$statusMsg = $status;
}
my $url = hostname_long ;
my $sender = $config{'notification_sender'} || my $sender = $config{'notification_sender'} ||
(($ENV{'USER'} || "hydra") . "@" . hostname_long); (($ENV{'USER'} || "hydra") . "@" . $url);
my $selfURI = $config{'base_uri'} || "http://localhost:3000"; my $selfURI = $config{'base_uri'} || "http://localhost:3000";
@ -153,7 +162,7 @@ sub sendEmailNotification {
my $body = "Hi,\n" my $body = "Hi,\n"
. "\n" . "\n"
. "This is to let you know that Hydra build " . $build->id . "This is to let you know that Hydra build " . $build->id
. " of job " . $jobName . " has $statusMsg.\n" . " of job " . $jobName . " " . (defined $prevBuild ? "has changed from '".statusDescription($prevBuild->resultInfo->buildstatus)."' to '$status'" : "has succeeded" ) .".\n"
. "\n" . "\n"
. "Complete build information can be found on this page: " . "Complete build information can be found on this page: "
. "$selfURI/build/" . $build->id . "\n" . "$selfURI/build/" . $build->id . "\n"
@ -180,7 +189,12 @@ sub sendEmailNotification {
header => [ header => [
To => $to, To => $to,
From => "Hydra Build Daemon <$sender>", From => "Hydra Build Daemon <$sender>",
Subject => "Hydra job $jobName build " . $build->id . " $status", Subject => "Hydra job $jobName build " . $build->id . ": $status",
'X-Hydra-Instance' => $url,
'X-Hydra-Project' => $build->project->name,
'X-Hydra-Jobset' => $build->jobset->name,
'X-Hydra-Job' => $build->job->name
], ],
body => "", body => "",
); );
@ -188,7 +202,7 @@ sub sendEmailNotification {
print $email->as_string if $ENV{'HYDRA_MAIL_TEST'}; print $email->as_string if $ENV{'HYDRA_MAIL_TEST'};
sendmail($email); sendmail($email);
} }

View file

@ -55,11 +55,12 @@ sub sendJobsetErrorNotification() {
return if $jobset->project->owner->emailonerror == 0; return if $jobset->project->owner->emailonerror == 0;
return if $errorMsg eq ""; return if $errorMsg eq "";
my $url = hostname_long;
my $projectName = $jobset->project->name; my $projectName = $jobset->project->name;
my $jobsetName = $jobset->name; my $jobsetName = $jobset->name;
my $sender = $config{'notification_sender'} || my $sender = $config{'notification_sender'} ||
(($ENV{'USER'} || "hydra") . "@" . hostname_long); (($ENV{'USER'} || "hydra") . "@" . $url);
my $body = "Hi,\n" my $body = "Hi,\n"
. "\n" . "\n"
@ -75,6 +76,10 @@ sub sendJobsetErrorNotification() {
To => $jobset->project->owner->emailaddress, To => $jobset->project->owner->emailaddress,
From => "Hydra Build Daemon <$sender>", From => "Hydra Build Daemon <$sender>",
Subject => "Hydra $projectName:$jobsetName evaluation error", Subject => "Hydra $projectName:$jobsetName evaluation error",
'X-Hydra-Instance' => $url,
'X-Hydra-Project' => $projectName,
'X-Hydra-Jobset' => $jobsetName
], ],
body => "" body => ""
); );