Created
July 15, 2013 20:05
-
-
Save mlbright/6002963 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use BuildForge::Services; | |
use Try::Tiny; | |
use File::Slurp; | |
use Cwd 'abs_path'; | |
my $USAGE = <<"USAGE"; | |
$0 <Build Forge project> [<Build Forge project>] | |
USAGE | |
if ( scalar(@ARGV) < 1 ) { | |
print $USAGE; | |
exit(1); | |
} | |
main( get_credentials(), \@ARGV ); | |
sub get_config_name { | |
my $name = abs_path($0); | |
my @parts = split( /\//, $name ); | |
my $config = $parts[-1]; | |
$name =~ s/$config$/.$config/; | |
return $name; | |
} | |
sub get_credentials { | |
my $config = get_config_name(); | |
if ( -e "$config" ) { | |
# Newline delimited string (file) containing: | |
# server | |
# api user | |
# api user's password | |
my $creds = read_file($config); | |
return split( /\n/, $creds ); | |
} | |
else { | |
print "Missing credentials file: $config\n"; | |
exit(1); | |
} | |
} | |
sub launch_if_possible { | |
my ( $conn, $name ) = @_; | |
my $proj = BuildForge::Services::DBO::Project->findByName( $conn, $name ); | |
my $id = $proj->getProjectId(); | |
my $selector_id = $proj->getSelectorId(); | |
my $selector = | |
BuildForge::Services::DBO::Selector->findById( $conn, $selector_id ); | |
my $selector_property = $selector->getProperty('BF_NAME'); | |
my $bf_name = $selector_property->getPropertyValue(); | |
my $server = | |
BuildForge::Services::DBO::Server->findByName( $conn, $bf_name ); | |
my $manifest = $server->getManifest(); | |
my $num_jobs = $manifest->getPropertyValue('BF_JOBS'); | |
if ( $num_jobs == 0 ) { | |
BuildForge::Services::DBO::Build->fire( $conn, $id ); | |
} | |
} | |
sub main { | |
my ( $server, $user, $pass, $repotests ) = @_; | |
exit; | |
my $conn = try { BuildForge::Services::Connection->new($server) } | |
catch { | |
print "Error connecting to $server ... Aborting.\n"; | |
exit(1); | |
}; | |
my $token = try { $conn->authUser( $user, $pass ) } | |
catch { | |
print "Could not authenticate to $server ... Aborting.\n"; | |
try { $conn->close() }; | |
exit(1); | |
}; | |
for my $repotest (@$repotests) { | |
launch_if_possible( $conn, $repotest ); | |
} | |
# No need to logout, just close connection | |
try { $conn->close() }; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment