RunCommand: Allow displaying command output
This commit is contained in:
@ -137,6 +137,15 @@ sub view_log : Chained('buildChain') PathPart('log') {
|
||||
}
|
||||
|
||||
|
||||
sub view_runcommand_log : Chained('buildChain') PathPart('runcommand-log') {
|
||||
my ($self, $c, $sha) = @_;
|
||||
|
||||
$c->stash->{is_runcommand} = 1;
|
||||
$c->stash->{log_uri} = $c->uri_for($c->controller('Root')->action_for("runcommandlog"), $sha . "-" . $c->stash->{build}->id);
|
||||
$c->stash->{template} = 'log.tt';
|
||||
}
|
||||
|
||||
|
||||
sub showLog {
|
||||
my ($c, $mode, $finished, $drvPath) = @_;
|
||||
$mode //= "pretty";
|
||||
|
@ -7,6 +7,7 @@ use base 'Hydra::Base::Controller::ListBuilds';
|
||||
use Hydra::Helper::Nix;
|
||||
use Hydra::Helper::CatalystUtils;
|
||||
use Hydra::View::TT;
|
||||
use Hydra::Model::DB;
|
||||
use Nix::Store;
|
||||
use Nix::Config;
|
||||
use Encode;
|
||||
@ -530,4 +531,20 @@ sub log :Local :Args(1) {
|
||||
}
|
||||
}
|
||||
|
||||
sub runcommandlog :Local :Args(1) {
|
||||
my ($self, $c, $filename) = @_;
|
||||
|
||||
my $tail = $c->request->params->{"tail"};
|
||||
|
||||
die if defined $tail && $tail !~ /^[0-9]+$/;
|
||||
|
||||
my $logFile = Hydra::Model::DB::getHydraPath . "/runcommand-logs/" . substr($filename, 0, 2) . "/$filename";
|
||||
if (-f $logFile) {
|
||||
serveLogFile($c, $logFile, $tail);
|
||||
return;
|
||||
} else {
|
||||
notFound($c, "The RunCommand log is not available.");
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -152,6 +152,8 @@ __PACKAGE__->belongs_to(
|
||||
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:9AIzlQl1RjRXrs9gQCZKVw
|
||||
|
||||
use POSIX qw(WEXITSTATUS WIFEXITED WIFSIGNALED WTERMSIG);
|
||||
use Digest::SHA1 qw(sha1_hex);
|
||||
use Hydra::Model::DB;
|
||||
|
||||
=head2 started
|
||||
|
||||
@ -321,3 +323,29 @@ sub did_fail_with_exec_error {
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head2 log_relative_url
|
||||
|
||||
Returns the URL to the log file relative to the build it belongs to.
|
||||
|
||||
Return:
|
||||
|
||||
* The relative URL if a log file exists
|
||||
* An empty string otherwise
|
||||
=cut
|
||||
sub log_relative_url() {
|
||||
my ($self) = @_;
|
||||
|
||||
# Do not return a URL when there is no build yet
|
||||
if (not defined($self->start_time)) {
|
||||
return "";
|
||||
}
|
||||
|
||||
my $sha = sha1_hex($self->command);
|
||||
# Do not return a URL when there is no log file yet
|
||||
if (not -f Hydra::Model::DB::getHydraPath . "/runcommand-logs/" . substr($sha, 0, 2) . "/$sha-" . $self->build_id) {
|
||||
return "";
|
||||
}
|
||||
|
||||
return "runcommand-log/$sha";
|
||||
}
|
||||
|
Reference in New Issue
Block a user