| 1 | #!/usr/bin/env perl | ||
| 2 | use Net::Jenkins; | ||
| 3 | use Jenkins::NotificationListener; | ||
| 4 | use Getopt::Long; | ||
| 5 | use AnyEvent; | ||
| 6 | use JSON::XS; | ||
| 7 | use YAML; | ||
| 8 | |||
| 9 | my $host = '127.0.0.1'; | ||
| 10 | my $port = 8888; | ||
| 11 | my $debug; | ||
| 12 | my $result = GetOptions( | ||
| 13 | 'host=s' => \$host, | ||
| 14 | 'port=i' => \$port, | ||
| 15 | 'd|debug' => \$debug, | ||
| 16 | ); | ||
| 17 | |||
| 18 | print "Listening at $host:$port...\n"; | ||
| 19 | Jenkins::NotificationListener->new( host => $host , port => $port , on_notify => sub { | ||
| 20 | my $payload = shift; # Jenkins::Notification; | ||
| 21 | |||
| 22 | if( $debug ) { | ||
| 23 | my $args = decode_json $payload->raw_json; | ||
| 24 | print "===== Payload Start =====\n"; | ||
| 25 | print Dump $args; | ||
| 26 | } | ||
| 27 | |||
| 28 | |||
| 29 | print $payload->name , " #" , $payload->build->number, " : " , $payload->status | ||
| 30 | , " : " , $payload->phase | ||
| 31 | , " : " , $payload->url | ||
| 32 | , "\n"; | ||
| 33 | |||
| 34 | })->start; | ||
| 35 | |||
| 36 | |||
| 37 | AnyEvent->condvar->recv; |