If multiple dependent builds fail, send a single email

[?]
May 9, 2013, 9:39 AM
QDJRQIFFTRQZ6GWIQD33R6RZ4AOW6F5IOFGSLSUU35E4QR454K7AC

Dependencies

Change contents

  • edit in src/lib/Hydra/Plugin/EmailNotification.pm at line 15
    [3.331]
    [3.331]
    use Hydra::Helper::CatalystUtils;
  • edit in src/lib/Hydra/Plugin/EmailNotification.pm at line 30
    [3.669]
    [3.669]
    }
    sub getPrevBuild {
    my ($self, $build) = @_;
    return $self->{db}->resultset('Builds')->search(
    { project => $build->project->name
    , jobset => $build->jobset->name
    , job => $build->job->name
    , system => $build->system
    , finished => 1
    , id => { '<', $build->id }
    , -not => { buildstatus => { -in => [4, 3]} }
    }, { order_by => ["id DESC"], rows => 1 }
    )->single;
    }
    sub showJobName {
    my ($build) = @_;
    return $build->project->name . ":" . $build->jobset->name . ":" . $build->job->name;
  • edit in src/lib/Hydra/Plugin/EmailNotification.pm at line 58
    [3.783]
    [3.783]
    # 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;
  • replacement in src/lib/Hydra/Plugin/EmailNotification.pm at line 67
    [3.784][3.784:803](),[3.803][2.72:133](),[2.133][3.856:1174](),[3.856][3.856:1174]()
    my $prevBuild;
    ($prevBuild) = $self->{db}->resultset('Builds')->search(
    { project => $build->project->name
    , jobset => $build->jobset->name
    , job => $build->job->name
    , system => $build->system
    , finished => 1
    , id => { '<', $build->id }
    , -not => { buildstatus => { -in => [4, 3]} }
    }, { order_by => ["id DESC"] }
    );
    [3.784]
    [3.1174]
    foreach my $address (split ",", $to) {
    $address = trim $address;
    # Do we want to send mail for this build?
    unless ($ENV{'HYDRA_FORCE_SEND_MAIL'}) {
    next unless $b->jobset->enableemail;
  • replacement in src/lib/Hydra/Plugin/EmailNotification.pm at line 74
    [3.1175][3.1175:1372]()
    # Do we want to send mail?
    unless ($ENV{'HYDRA_FORCE_SEND_MAIL'}) {
    return unless $build->jobset->enableemail && ($build->maintainers ne "" || $build->jobset->emailoverride ne "");
    [3.1175]
    [3.1372]
    # If build is cancelled or aborted, do not send email.
    next if $b->buildstatus == 4 || $b->buildstatus == 3;
  • replacement in src/lib/Hydra/Plugin/EmailNotification.pm at line 77
    [3.1373][3.1373:1508]()
    # If build is cancelled or aborted, do not send email.
    return if $build->buildstatus == 4 || $build->buildstatus == 3;
    [3.1373]
    [3.1508]
    # If there is a previous (that is not cancelled or aborted) build
    # with same buildstatus, do not send email.
    next if defined $prevBuild && ($b->buildstatus == $prevBuild->buildstatus);
    }
  • replacement in src/lib/Hydra/Plugin/EmailNotification.pm at line 82
    [3.1509][3.1509:1725]()
    # 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);
    [3.1509]
    [3.1725]
    $addresses{$address} //= { builds => [] };
    push @{$addresses{$address}->{builds}}, $b;
    }
  • replacement in src/lib/Hydra/Plugin/EmailNotification.pm at line 87
    [3.1732][3.1732:1749]()
    # Send mail.
    [3.1732]
    [3.1749]
    # Send an email to each interested address.
  • replacement in src/lib/Hydra/Plugin/EmailNotification.pm at line 90
    [3.1798][3.1798:1966]()
    my $to = (!$build->jobset->emailoverride eq "") ? $build->jobset->emailoverride : $build->maintainers;
    print STDERR "sending mail notification to ", $to, "\n";
    [3.1798]
    [3.1966]
    for my $to (keys %addresses) {
    print STDERR "sending mail notification to ", $to, "\n";
    my @builds = @{$addresses{$to}->{builds}};
  • replacement in src/lib/Hydra/Plugin/EmailNotification.pm at line 94
    [3.1967][3.1967:2063]()
    my $jobName = $build->project->name . ":" . $build->jobset->name . ":" . $build->job->name;
    [3.1967]
    [3.2063]
    my $jobName = showJobName $build;
  • replacement in src/lib/Hydra/Plugin/EmailNotification.pm at line 96
    [3.2064][3.2064:2121]()
    my $status = statusDescription($build->buildstatus);
    [3.2064]
    [3.2121]
    my $status = statusDescription($build->buildstatus);
  • replacement in src/lib/Hydra/Plugin/EmailNotification.pm at line 98
    [3.2122][3.2122:2155](),[3.2155][2.134:195](),[2.195][3.2208:2263](),[3.2208][3.2208:2263]()
    my $baseurl = hostname_long;
    my $sender = $self->{config}->{'notification_sender'} ||
    (($ENV{'USER'} || "hydra") . "@" . $baseurl);
    [3.2122]
    [3.2263]
    my $baseurl = hostname_long;
    my $sender = $self->{config}->{'notification_sender'} ||
    (($ENV{'USER'} || "hydra") . "@" . $baseurl);
  • replacement in src/lib/Hydra/Plugin/EmailNotification.pm at line 102
    [3.2264][2.196:272]()
    my $selfURI = $self->{config}->{'base_uri'} || "http://localhost:3000";
    [3.2264]
    [3.2332]
    my $selfURI = $self->{config}->{'base_uri'} || "http://localhost:3000";
  • replacement in src/lib/Hydra/Plugin/EmailNotification.pm at line 104
    [3.2333][3.2333:2421]()
    sub showTime { my ($x) = @_; return strftime('%Y-%m-%d %H:%M:%S', localtime($x)); }
    [3.2333]
    [3.2421]
    sub showTime { my ($x) = @_; return strftime('%Y-%m-%d %H:%M:%S', localtime($x)); }
  • replacement in src/lib/Hydra/Plugin/EmailNotification.pm at line 106
    [3.2422][3.2422:3238]()
    my $infoTable = Text::Table->new({ align => "left" }, \ " | ", { align => "left" });
    my @lines = (
    [ "Build ID:", $build->id ],
    [ "Nix name:", $build->nixname ],
    [ "Short description:", $build->description || '(not given)' ],
    [ "Maintainer(s):", $build->maintainers ],
    [ "System:", $build->system ],
    [ "Derivation store path:", $build->drvpath ],
    [ "Output store path:", join(", ", map { $_->path } $build->buildoutputs) ],
    [ "Time added:", showTime $build->timestamp ],
    );
    push @lines, (
    [ "Build started:", showTime $build->starttime ],
    [ "Build finished:", showTime $build->stoptime ],
    [ "Duration:", $build->stoptime - $build->starttime . "s" ],
    ) if $build->starttime;
    $infoTable->load(@lines);
    [3.2422]
    [3.3238]
    my $infoTable = Text::Table->new({ align => "left" }, \ " | ", { align => "left" });
    my @lines = (
    [ "Build ID:", $build->id ],
    [ "Nix name:", $build->nixname ],
    [ "Short description:", $build->description || '(not given)' ],
    [ "Maintainer(s):", $build->maintainers ],
    [ "System:", $build->system ],
    [ "Derivation store path:", $build->drvpath ],
    [ "Output store path:", join(", ", map { $_->path } $build->buildoutputs) ],
    [ "Time added:", showTime $build->timestamp ],
    );
    push @lines, (
    [ "Build started:", showTime $build->starttime ],
    [ "Build finished:", showTime $build->stoptime ],
    [ "Duration:", $build->stoptime - $build->starttime . "s" ],
    ) if $build->starttime;
    $infoTable->load(@lines);
  • replacement in src/lib/Hydra/Plugin/EmailNotification.pm at line 124
    [3.3239][3.3239:3909]()
    my $inputsTable = Text::Table->new(
    { title => "Name", align => "left" }, \ " | ",
    { title => "Type", align => "left" }, \ " | ",
    { title => "Value", align => "left" });
    @lines = ();
    foreach my $input ($build->inputs) {
    my $type = $input->type;
    push @lines,
    [ $input->name
    , $input->type
    , ( $input->type eq "build" || $input->type eq "sysbuild")
    ? $input->dependency->id
    : ($input->type eq "string" || $input->type eq "boolean")
    ? $input->value : ($input->uri . ':' . $input->revision)
    ];
    }
    $inputsTable->load(@lines);
    [3.3239]
    [3.3909]
    my $inputsTable = Text::Table->new(
    { title => "Name", align => "left" }, \ " | ",
    { title => "Type", align => "left" }, \ " | ",
    { title => "Value", align => "left" });
    @lines = ();
    foreach my $input ($build->inputs) {
    my $type = $input->type;
    push @lines,
    [ $input->name
    , $input->type
    , ( $input->type eq "build" || $input->type eq "sysbuild")
    ? $input->dependency->id
    : ($input->type eq "string" || $input->type eq "boolean")
    ? $input->value : ($input->uri . ':' . $input->revision)
    ];
    }
    $inputsTable->load(@lines);
  • replacement in src/lib/Hydra/Plugin/EmailNotification.pm at line 142
    [3.3910][3.3910:4037]()
    my $loglines = 50;
    my $logtext = logContents($build->drvpath, $loglines);
    $logtext = removeAsciiEscapes($logtext);
    [3.3910]
    [3.4037]
    my $loglines = 50;
    my $logtext = logContents($build->drvpath, $loglines);
    $logtext = removeAsciiEscapes($logtext);
  • replacement in src/lib/Hydra/Plugin/EmailNotification.pm at line 146
    [3.4038][3.4038:4986]()
    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"
    . "\n"
    . "Complete build information can be found on this page: "
    . "$selfURI/build/" . $build->id . "\n"
    . ($build->buildstatus != 0 ? "\nThe last $loglines lines of the build log are shown at the bottom of this email.\n" : "")
    . "\n"
    . "A summary of the build information follows:\n"
    . "\n"
    . $infoTable->body
    . "\n"
    . "The build inputs were:\n"
    . "\n"
    . $inputsTable->title
    . $inputsTable->rule('-', '+')
    . $inputsTable->body
    . "\n"
    . "Regards,\n\nThe Hydra build daemon.\n"
    . ($build->buildstatus != 0 ? "\n---\n$logtext" : "");
    [3.4038]
    [3.4986]
    my $prevBuild = getPrevBuild($self, $build);
  • replacement in src/lib/Hydra/Plugin/EmailNotification.pm at line 148
    [3.4987][3.4987:5057]()
    # stripping trailing spaces from lines
    $body =~ s/[\ ]+$//gm;
    [3.4987]
    [3.5057]
    my $foo = "\nIn addition, the following jobs failed:\n";
    foreach my $b (@builds) {
    $foo .= " " . showJobName($b) . " ($selfURI/build/" . $b->id . ")\n";
    }
  • replacement in src/lib/Hydra/Plugin/EmailNotification.pm at line 153
    [3.5058][3.5058:5627]()
    my $email = Email::Simple->create(
    header => [
    To => $to,
    From => "Hydra Build Daemon <$sender>",
    Subject => "$status: Hydra job $jobName on " . $build->system . ", build " . $build->id,
    'X-Hydra-Instance' => $baseurl,
    'X-Hydra-Project' => $build->project->name,
    'X-Hydra-Jobset' => $build->jobset->name,
    'X-Hydra-Job' => $build->job->name,
    'X-Hydra-System' => $build->system
    ],
    body => "",
    );
    $email->body_set($body);
    [3.5058]
    [3.5627]
    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"
    . ($build->buildstatus != 0 ? "\nThe last $loglines lines of the build log are shown at the bottom of this email.\n" : "")
    . "\n"
    . "A summary of the build information follows:\n"
    . "\n"
    . $infoTable->body
    . "\n"
    . "The build inputs were:\n"
    . "\n"
    . $inputsTable->title
    . $inputsTable->rule('-', '+')
    . $inputsTable->body
    . "\n"
    . "Regards,\n\nThe Hydra build daemon.\n"
    . ($build->buildstatus != 0 ? "\n---\n$logtext" : "");
    # stripping trailing spaces from lines
    $body =~ s/[\ ]+$//gm;
    my $email = Email::Simple->create(
    header => [
    To => $to,
    From => "Hydra Build Daemon <$sender>",
    Subject => "$status: Hydra job $jobName on " . $build->system . ", build " . $build->id,
    'X-Hydra-Instance' => $baseurl,
    'X-Hydra-Project' => $build->project->name,
    'X-Hydra-Jobset' => $build->jobset->name,
    'X-Hydra-Job' => $build->job->name,
    'X-Hydra-System' => $build->system
    ],
    body => "",
    );
    $email->body_set($body);
  • replacement in src/lib/Hydra/Plugin/EmailNotification.pm at line 194
    [3.5628][3.5628:5850]()
    if (defined $ENV{'HYDRA_MAIL_SINK'}) {
    # For testing, redirect all mail to a file.
    write_file($ENV{'HYDRA_MAIL_SINK'}, { append => 1 }, $email->as_string . "\n");
    } else {
    sendmail($email);
    [3.5628]
    [3.5850]
    if (defined $ENV{'HYDRA_MAIL_SINK'}) {
    # For testing, redirect all mail to a file.
    write_file($ENV{'HYDRA_MAIL_SINK'}, { append => 1 }, $email->as_string . "\n");
    } else {
    sendmail($email);
    }