I got strange behavior of Jenkins post build task script. its purpose is showing build error in slack like following.
EDIT: our Jenkins running on Mac OSX Yosemite (10.10.4) and using Unity3d as build tool.
SLACK_BOT_PATH=$WORKSPACE/tools/bot.rb
SLACK_BOT_NAME="cortana"
SLACK_BOT_TOKEN=`cat $WORKSPACE/../../sendchat_token`
ERRORS=`tail -5000 ~/Library/Logs/Unity/Editor${BUILD_NUMBER}.log | grep ": error"`
ruby $SLACK_BOT_PATH $SLACK_BOT_NAME $SLACK_BOT_TOKEN "build fails : $ERRORS"
and strange behavior is, it aborted on the ERRORS= line when ERRORS has no contents (empty string). Jenkins console output is like following.
[workspace] $ /bin/sh -xe /var/folders/j3/8x825bdn2l9dm497yjs2144c0000gn/T/hudson7348609981772923445.sh
+ SLACK_BOT_PATH=*snip*
+ SLACK_BOT_NAME=cortana
++ cat *snip*/../../sendchat_token
+ SLACK_BOT_TOKEN=*snip*
++ tail -5000 ~/Library/Logs/Unity/Editor1710.log
++ grep ': error'
+ ERRORS=
POST BUILD TASK : FAILURE
after I change grep filter so that ERRORS has some contents, the post build script runs correctly again.
I want to report some general error message (eg. build fails) when no actual ERRORS found in logs. but also report detail error message when its available.
of course it is easy that inserting some line to send general message before grep error log so that every time such a general message sent to slack, but I want know the reason why empty ERRORS terminate entire script.
does anyone encounter same issue? if so, finally you know the cause of problem? thanks.