Reputation: 1461
I have a Jenkins job that executes a "foo.sh" and "bar.sh", and those scripts produce "foo.log", "bar.log" respectively. foo.sh and bar.sh are long running jobs, and I wan't to view their log files unified in the "Console Output" view of jenkins.
I know I can archive these logs as build artifacts, but I want to monitor all 3 logs ("Console Output"/stdout, foo.log and bar.log) from one view - Console Output.
Is there a plugin or configuration option that will let me do this?
Note: foo.sh
and bar.sh
are obviously placeholders, but I'm afraid they're from a vendor and I cannot modify them to adjust logging behavior.
Upvotes: 0
Views: 1812
Reputation: 27485
Assume your files are under $WORKSPACE
:
tail -F *.log
Edit:
Or you could consider re-writing your foo.sh
and bar.sh
, but instead of redirecting to log file, tee
to console and log file.
echo "doing stuff" 2>&1|tee -a foo.log
Above will print to console (which is displayed in Jenkins console output), and redirect to foo.log
Edit 2:
If you have no control over foo.sh
and bar.sh
, you would need a wrapping script to launch them with some trickery.
Basically, after you send foo.sh
to background (so that we can continue), before you tail
the log, you need to ensure that tail
would be killed. We do this by launching another background process to monitor foo.sh
process and kill tail
(that is yet to be launched in script). As we haven't launched tail
yet, we don't really know what its PID would be, hence we refer to it through command line
# Send foo.sh to background and record the PID
echo "Launching foo.sh to background"
nohup ./foo.sh &
foo_pid=$!
echo "Foo PID to monitor=$foo_pid"
# Launch a statement that will run ever 3 seconds to monitor status
# of foo.sh, and if foo.sh finished, then kill a 'future' tail command
echo "Launching tail-killer to background"
nohup $(sleep 3; while kill -0 $foo_pid; do sleep 3; done; kill $(ps --no-heading -C "tail -F foo.log" | awk '{print $1}') ) &
# Tail foo.sh's log
echo "Launching tail to monitor foo.sh"
echo
tail -F foo.log
echo
# Get the return code of foo.sh
wait $foo_pid
echo "Foo.sh returned with $?
Considerations/improvements:
Foo.sh
could print more than 10 lines after start, before tail
is called. Use tail -n
to increase the number of starting lines.tail -F foo.log
detected. You should modify it to be more robustUpvotes: 2