From 4cb5e6cd9414ed24e3f046c31a84aec3f50269be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Janne=20He=C3=9F?= Date: Sun, 26 Dec 2021 16:14:10 +0100 Subject: [PATCH] RunCommand: Capture the output of the commands --- hydra-module.nix | 7 ++++++- src/lib/Hydra/Plugin/RunCommand.pm | 15 ++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/hydra-module.nix b/hydra-module.nix index 03265c66..e3d7e614 100644 --- a/hydra-module.nix +++ b/hydra-module.nix @@ -275,7 +275,11 @@ in mkdir -m 0700 -p ${baseDir}/queue-runner mkdir -m 0750 -p ${baseDir}/build-logs - chown hydra-queue-runner.hydra ${baseDir}/queue-runner ${baseDir}/build-logs + mkdir -m 0750 -p ${baseDir}/runcommand-logs + chown hydra-queue-runner.hydra \ + ${baseDir}/queue-runner \ + ${baseDir}/build-logs \ + ${baseDir}/runcommand-logs ${optionalString haveLocalDB '' if ! [ -e ${baseDir}/.db-created ]; then @@ -457,6 +461,7 @@ in script = '' find /var/lib/hydra/build-logs -type f -name "*.drv" -mtime +3 -size +0c | xargs -r bzip2 -v -f + find /var/lib/hydra/runcommand-logs -type f -name "*.drv" -mtime +3 -size +0c | xargs -r bzip2 -v -f ''; startAt = "Sun 01:45"; }; diff --git a/src/lib/Hydra/Plugin/RunCommand.pm b/src/lib/Hydra/Plugin/RunCommand.pm index 36c77ce4..096bf1c1 100644 --- a/src/lib/Hydra/Plugin/RunCommand.pm +++ b/src/lib/Hydra/Plugin/RunCommand.pm @@ -5,6 +5,8 @@ use warnings; use parent 'Hydra::Plugin'; use experimental 'smartmatch'; use JSON::MaybeXS; +use Digest::SHA1 qw(sha1_hex); +use Hydra::Model::DB; sub isEnabled { my ($self) = @_; @@ -160,7 +162,18 @@ sub buildFinished { $runlog->started(); - system("$command") == 0 + # Prepare log collection + my $filename = sha1_hex($command) . "-" . $build->get_column('id'); + my $dir = Hydra::Model::DB::getHydraPath . "/runcommand-logs/" . substr($filename, 0, 2); + my $logpath = "$dir/$filename"; + mkdir($dir, oct(755)); + # This creates the file with the correct permissions + open(my $f, '>', $logpath); + close($f); + chmod(oct(644), $logpath); + + # Run the command + system("$command 1>$logpath 2>&1") == 0 or warn "notification command '$command' failed with exit status $? ($!)\n"; $runlog->completed_with_child_error($?, $!);