* added support for twitter notification
3 environment variables are important: TWITTER_USER TWITTER_PASS HYDRA_BUILD_BASEURL - twitter notification is off when TWITTER_USER and TWITTER_PASS are not defined - if HYDRA_BUILD_BASEURL is not defined, no URL is put in the twitter messages
This commit is contained in:
parent
3e03ac9a7c
commit
1c5ab05521
1
deps.nix
1
deps.nix
|
@ -18,5 +18,6 @@ with pkgs;
|
||||||
perlPackages.EmailSender
|
perlPackages.EmailSender
|
||||||
perlPackages.EmailSimpleCreator
|
perlPackages.EmailSimpleCreator
|
||||||
perlPackages.TextTable
|
perlPackages.TextTable
|
||||||
|
perlPackages.NetTwitterLite
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ use Sys::Hostname::Long;
|
||||||
use Config::General;
|
use Config::General;
|
||||||
use Text::Table;
|
use Text::Table;
|
||||||
use POSIX qw(strftime);
|
use POSIX qw(strftime);
|
||||||
|
use Net::Twitter::Lite;
|
||||||
|
|
||||||
|
|
||||||
STDOUT->autoflush();
|
STDOUT->autoflush();
|
||||||
|
@ -29,6 +30,35 @@ sub getBuildLog {
|
||||||
return -e $logPath ? $logPath : undef;
|
return -e $logPath ? $logPath : undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub sendTwitterNotification {
|
||||||
|
my ($build) = @_;
|
||||||
|
|
||||||
|
return unless (defined $ENV{'TWITTER_USER'} && defined $ENV{'TWITTER_PASS'});
|
||||||
|
|
||||||
|
my $addURL = defined $ENV{'HYDRA_BUILD_BASEURL'};
|
||||||
|
|
||||||
|
my $jobName = $build->project->name . ":" . $build->jobset->name . ":" . $build->job->name;
|
||||||
|
my $status = $build->resultInfo->buildstatus == 0 ? "SUCCEEDED" : "FAILED";
|
||||||
|
my $system = $build->system;
|
||||||
|
my $duration = ($build->resultInfo->stoptime - $build->resultInfo->starttime) . " seconds";
|
||||||
|
my $url = $ENV{'HYDRA_BUILD_BASEURL'}."/".$build->id ;
|
||||||
|
|
||||||
|
my $nt = Net::Twitter::Lite->new(
|
||||||
|
username => $ENV{'TWITTER_USER'},
|
||||||
|
password => $ENV{'TWITTER_PASS'}
|
||||||
|
);
|
||||||
|
|
||||||
|
my $tag = $build->project->name;
|
||||||
|
my $msg = "$jobName ($system): $status in $duration #$tag";
|
||||||
|
if (length($msg) + 1 + length($url) <= 140) {
|
||||||
|
$msg = "$msg $url" ;
|
||||||
|
}
|
||||||
|
|
||||||
|
eval {
|
||||||
|
my $result = eval { $nt->update($msg) };
|
||||||
|
};
|
||||||
|
warn "$@\n" if $@;
|
||||||
|
}
|
||||||
|
|
||||||
sub sendEmailNotification {
|
sub sendEmailNotification {
|
||||||
my ($build) = @_;
|
my ($build) = @_;
|
||||||
|
@ -374,6 +404,7 @@ sub doBuild {
|
||||||
});
|
});
|
||||||
|
|
||||||
sendEmailNotification $build;
|
sendEmailNotification $build;
|
||||||
|
sendTwitterNotification $build;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -384,6 +415,10 @@ if ($ENV{'HYDRA_MAIL_TEST'}) {
|
||||||
sendEmailNotification $db->resultset('Builds')->find($buildId);
|
sendEmailNotification $db->resultset('Builds')->find($buildId);
|
||||||
exit 0;
|
exit 0;
|
||||||
}
|
}
|
||||||
|
if ($ENV{'HYDRA_TWITTER_TEST'}) {
|
||||||
|
sendTwitterNotification $db->resultset('Builds')->find($buildId);
|
||||||
|
exit 0;
|
||||||
|
}
|
||||||
|
|
||||||
# Lock the build. If necessary, steal the lock from the parent
|
# Lock the build. If necessary, steal the lock from the parent
|
||||||
# process (runner.pl). This is so that if the runner dies, the
|
# process (runner.pl). This is so that if the runner dies, the
|
||||||
|
|
Loading…
Reference in a new issue