I am trying to create batches to achieve Nightly build under Windows. I managed to compile in release and debug automatically produce via a script.
But now I would like to be notified if there is an error during compilation and the need to return an email if this fails. This raises the following question:
Will I return an error nmake? Or rather the batch itself if it fails?
And if so, how I can return this error in a text file or an email?
I'm running under à Windows Server 2012 and use the task scheduler to automate. And here is my batch (EDITED) :
@echo on
echo[
set rel=release
@echo ####### COMPILATION CORE (DEBUG / x86) #######
echo[
cd C:\Users\mea\Documents\Repos\corealpi\cmake\nmake
@echo ####### delete cache #######
rm -R *
@echo ####### Generation of Makefile #######
call "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat"
cmake -DCMAKE_BUILD_TYPE=Debug -G"NMake Makefiles" ../
if %errorlevel% neq 0 goto mailcmaked
@echo ####### compilation of core #######
echo[
nmake
if %errorlevel% neq 0 goto mailnmaked
pause
@echo ####### COMPILATION CORE(RELEASE / x86) #######
echo[
cd C:\Users\mea\Documents\Repos\corealpi\cmake\nmake
@echo ####### Suppression du CACHE #######
rm -R *
@echo ####### Generation of Makefile #######
call "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat"
cmake -DCMAKE_BUILD_TYPE=Release -G"NMake Makefiles" ../
if %ERRORLEVEL% neq 0 goto mailcmaker
@echo ####### Compilation of CORE #######
echo[
>"..\log\buildRel.log" nmake
if %errorlevel% neq 0 goto mailnmaker
pause
:mailcmaked
echo Error!
sendEmail -f from@mail.com -t someone@mail.com -m "cmake debug failed" -s 192.168.x.x
exit 1
:mailnmaked
echo Error!
sendEmail -f from@mail.com -t someone@mail.com -m "nmake debug failed" -s 192.168.x.x
exit 1
:mailcmaker
sendEmail -f from@mail.com -t someone@mail.com -m "cmake release failed" -s 192.168.x.x
exit 1
:mailnmaker
grep -Eo '.{0,20}error.{0,100}' ..\log\buildRel.log > ..\log\mailBuild.txt
sendEmail -f from@mail.com -u "build failed" -t someone@mail.com -m "nmake release failed" -a ..\log\mailBuild.txt -s 192.168.x.x
exit 1
EDIT
I edited my script drawing inspiration from your example and now that's working great (just for the :mailnmaker
section for the moment). I organize my ouput with the grep command.
For the mail problem, i've just install sendEmail and put it in my Windows PATH and that's working.
Thank you for your help.