forked from lix-project/hydra
If multiple dependent builds fail, send a single email
This commit is contained in:
parent
038db3abeb
commit
b378d94087
|
@ -12,6 +12,7 @@ use Sys::Hostname::Long;
|
||||||
use Text::Table;
|
use Text::Table;
|
||||||
use File::Slurp;
|
use File::Slurp;
|
||||||
use Hydra::Helper::Nix;
|
use Hydra::Helper::Nix;
|
||||||
|
use Hydra::Helper::CatalystUtils;
|
||||||
|
|
||||||
|
|
||||||
sub statusDescription {
|
sub statusDescription {
|
||||||
|
@ -29,13 +30,9 @@ sub statusDescription {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
sub buildFinished {
|
sub getPrevBuild {
|
||||||
my ($self, $build, $dependents) = @_;
|
my ($self, $build) = @_;
|
||||||
|
return $self->{db}->resultset('Builds')->search(
|
||||||
die unless $build->finished;
|
|
||||||
|
|
||||||
my $prevBuild;
|
|
||||||
($prevBuild) = $self->{db}->resultset('Builds')->search(
|
|
||||||
{ project => $build->project->name
|
{ project => $build->project->name
|
||||||
, jobset => $build->jobset->name
|
, jobset => $build->jobset->name
|
||||||
, job => $build->job->name
|
, job => $build->job->name
|
||||||
|
@ -43,28 +40,58 @@ sub buildFinished {
|
||||||
, finished => 1
|
, finished => 1
|
||||||
, id => { '<', $build->id }
|
, id => { '<', $build->id }
|
||||||
, -not => { buildstatus => { -in => [4, 3]} }
|
, -not => { buildstatus => { -in => [4, 3]} }
|
||||||
}, { order_by => ["id DESC"] }
|
}, { order_by => ["id DESC"], rows => 1 }
|
||||||
);
|
)->single;
|
||||||
|
}
|
||||||
|
|
||||||
# Do we want to send mail?
|
|
||||||
|
sub showJobName {
|
||||||
|
my ($build) = @_;
|
||||||
|
return $build->project->name . ":" . $build->jobset->name . ":" . $build->job->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
sub buildFinished {
|
||||||
|
my ($self, $build, $dependents) = @_;
|
||||||
|
|
||||||
|
die unless $build->finished;
|
||||||
|
|
||||||
|
# Figure out to whom to send notification for each build. For
|
||||||
|
# each email address, we send one aggregate email listing only the
|
||||||
|
# relevant builds for that address.
|
||||||
|
my %addresses;
|
||||||
|
foreach my $b ($build, @{$dependents}) {
|
||||||
|
my $prevBuild = getPrevBuild($self, $b);
|
||||||
|
my $to = $b->jobset->emailoverride ne "" ? $b->jobset->emailoverride : $b->maintainers;
|
||||||
|
|
||||||
|
foreach my $address (split ",", $to) {
|
||||||
|
$address = trim $address;
|
||||||
|
|
||||||
|
# Do we want to send mail for this build?
|
||||||
unless ($ENV{'HYDRA_FORCE_SEND_MAIL'}) {
|
unless ($ENV{'HYDRA_FORCE_SEND_MAIL'}) {
|
||||||
return unless $build->jobset->enableemail && ($build->maintainers ne "" || $build->jobset->emailoverride ne "");
|
next unless $b->jobset->enableemail;
|
||||||
|
|
||||||
# If build is cancelled or aborted, do not send email.
|
# If build is cancelled or aborted, do not send email.
|
||||||
return if $build->buildstatus == 4 || $build->buildstatus == 3;
|
next if $b->buildstatus == 4 || $b->buildstatus == 3;
|
||||||
|
|
||||||
# If there is a previous (that is not cancelled or aborted) build
|
# If there is a previous (that is not cancelled or aborted) build
|
||||||
# with same buildstatus, do not send email.
|
# with same buildstatus, do not send email.
|
||||||
return if defined $prevBuild && ($build->buildstatus == $prevBuild->buildstatus);
|
next if defined $prevBuild && ($b->buildstatus == $prevBuild->buildstatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
# Send mail.
|
$addresses{$address} //= { builds => [] };
|
||||||
|
push @{$addresses{$address}->{builds}}, $b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Send an email to each interested address.
|
||||||
# !!! should use the Template Toolkit here.
|
# !!! should use the Template Toolkit here.
|
||||||
|
|
||||||
my $to = (!$build->jobset->emailoverride eq "") ? $build->jobset->emailoverride : $build->maintainers;
|
for my $to (keys %addresses) {
|
||||||
print STDERR "sending mail notification to ", $to, "\n";
|
print STDERR "sending mail notification to ", $to, "\n";
|
||||||
|
my @builds = @{$addresses{$to}->{builds}};
|
||||||
|
|
||||||
my $jobName = $build->project->name . ":" . $build->jobset->name . ":" . $build->job->name;
|
my $jobName = showJobName $build;
|
||||||
|
|
||||||
my $status = statusDescription($build->buildstatus);
|
my $status = statusDescription($build->buildstatus);
|
||||||
|
|
||||||
|
@ -116,10 +143,18 @@ sub buildFinished {
|
||||||
my $logtext = logContents($build->drvpath, $loglines);
|
my $logtext = logContents($build->drvpath, $loglines);
|
||||||
$logtext = removeAsciiEscapes($logtext);
|
$logtext = removeAsciiEscapes($logtext);
|
||||||
|
|
||||||
|
my $prevBuild = getPrevBuild($self, $build);
|
||||||
|
|
||||||
|
my $foo = "\nIn addition, the following jobs failed:\n";
|
||||||
|
foreach my $b (@builds) {
|
||||||
|
$foo .= " " . showJobName($b) . " ($selfURI/build/" . $b->id . ")\n";
|
||||||
|
}
|
||||||
|
|
||||||
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 . " " . (defined $prevBuild ? "has changed from '" . statusDescription($prevBuild->buildstatus) . "' to '$status'" : "is '$status'" ) .".\n"
|
. " of job " . $jobName . " " . (defined $prevBuild ? "has changed from '" . statusDescription($prevBuild->buildstatus) . "' to '$status'" : "is '$status'" ) .".\n"
|
||||||
|
. $foo
|
||||||
. "\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"
|
||||||
|
@ -163,6 +198,7 @@ sub buildFinished {
|
||||||
sendmail($email);
|
sendmail($email);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
Loading…
Reference in a new issue