I've got a CI server with a command-line interface that allows me to remotely kick-off a job (jenkins
CI server and the jenkins-cli.jar
tool).
After I kick the job off I tail -f
the log (sorry for the messy command):
ssh -t my-jenkins-host.com "tail -f \"/var/lib/jenkins/jobs/$job_name/builds/\`ls -ltr /var/lib/jenkins/jobs/$job_name/builds/ | grep '^l' | tail -n 1|awk '{print \$9}'\`/log\""
After the job successfully completes, usually after at least 5 minutes, I get the following line on the output:
Finished: SUCCESS
Is there a good way to stop tailing the log at this point? i.e. is there like a tail_until 'some line' my-file.log
command?
BONUS: extra credit if you can supply an answer that returns 0 when SUCCESS is matched, 1 when FAILURE is matched, and your solution works on mac! (which i believe is bsd based)
q
command takes an optional exit code. So thesed
command would besed '/^Finished: SUCCESS$/ q0; /^Finished: FAILURE$/ q1'
– Michael Mrozek Aug 20 '12 at 21:14Finished: SUCCESS
is the last line of output – lk- Aug 20 '12 at 21:15timeout
– Michael Mrozek Mar 15 '18 at 17:25tail
never actually exits and instead just hangs. I see this same behavior both on my Linux server (distro unknown) running Jenkins as well as on my development Mac. – ArtOfWarfare May 12 '21 at 18:48