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 File::Slurp;
|
||||
use Hydra::Helper::Nix;
|
||||
use Hydra::Helper::CatalystUtils;
|
||||
|
||||
|
||||
sub statusDescription {
|
||||
|
@ -29,13 +30,9 @@ sub statusDescription {
|
|||
}
|
||||
|
||||
|
||||
sub buildFinished {
|
||||
my ($self, $build, $dependents) = @_;
|
||||
|
||||
die unless $build->finished;
|
||||
|
||||
my $prevBuild;
|
||||
($prevBuild) = $self->{db}->resultset('Builds')->search(
|
||||
sub getPrevBuild {
|
||||
my ($self, $build) = @_;
|
||||
return $self->{db}->resultset('Builds')->search(
|
||||
{ project => $build->project->name
|
||||
, jobset => $build->jobset->name
|
||||
, job => $build->job->name
|
||||
|
@ -43,28 +40,58 @@ sub buildFinished {
|
|||
, finished => 1
|
||||
, id => { '<', $build->id }
|
||||
, -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'}) {
|
||||
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.
|
||||
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
|
||||
# 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.
|
||||
|
||||
my $to = (!$build->jobset->emailoverride eq "") ? $build->jobset->emailoverride : $build->maintainers;
|
||||
for my $to (keys %addresses) {
|
||||
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);
|
||||
|
||||
|
@ -116,10 +143,18 @@ sub buildFinished {
|
|||
my $logtext = logContents($build->drvpath, $loglines);
|
||||
$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"
|
||||
. "\n"
|
||||
. "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"
|
||||
. $foo
|
||||
. "\n"
|
||||
. "Complete build information can be found on this page: "
|
||||
. "$selfURI/build/" . $build->id . "\n"
|
||||
|
@ -163,6 +198,7 @@ sub buildFinished {
|
|||
sendmail($email);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
|
|
Loading…
Reference in a new issue