How to capture a specific log file and show its contents in jenkins Console exit

I have the following post-build Jenkins script shell:

ssh user@my _server <<EOF service my_service stop service my_service start tail -f /opt/services/my_service/logs/current exit EOF 

This script reloads my_service on the remote host (my_server).

My problem: the service command my_service start just makes a RUNIT request to start my_service, i.e. the my_service start service is returned immediately after execution.

But the my_service start service starts the SpringBoot java web application, which writes all the log information to ... / logs / the current log file. To catch this log information, I added the command tail -f / opt / services / my_service / logs / current , but in this case the Jenkins build never ends)), for example tail -f never stops.

Is there a way to execute my post-build script (which runs only my web application on a remote server) and capture the file ... / logs / current log for 2 minutes or until this log has the line "MyApplication web application started applications. "

I want to view the contents of ... / logs / of the current log file directly in the Jenkins console output and kill tail -f after 2 minutes

+5
source share
1 answer

tail -f will not end until it breaks, so your script will never end.

what you can do is use grep -q in your log, which will exit with 0 exit status when it finds a pattern:

 grep -q 'Web app MyApplication has been Started' <(tail -f /opt/services/my_service/logs/current) 
+2
source

Source: https://habr.com/ru/post/1239225/


All Articles