CruiseControl.NET & batch's %ERRORLEVEL%

I wanted to do a very simple thing using CruiseControl.NET - have a batch file that does some work be executed in my project and if error level is not "0" fail the test.

I started by creating a very simple Project with the Exec task that execute batch file called BuildHub.bat (for the sake of demo):

<project name="HUB" queue="SR_GUI">
  <workingDirectory>c:\temp</workingDirectory>
  <artifactDirectory>c:\temp</artifactDirectory>
  <sourcecontrol type="nullSourceControl" />
  <triggers>
    <projectTrigger project="SP Build" />
  </triggers>
  <tasks>
    <exec executable="BuildHub.bat" />
  </tasks>
</project>

 

The batch looks something like this:

@echo off

echo provision drive

... some lines script ...

Echo Debug: Error level = %ERRORLEVEL%

 

I started to check the project by running it and although I knew it should fail (I saw the debug note about error level = 9002) it always reported as succeeded.

initially I tough that because I used last action of echo then it might reset the error level but this wasn't the case (validated by running manually)

To make a long story short the resolution was to simply put the following line at the end of the batch:

Exit /B %ERRORLEVEL%

As always I hope this save you some time

CruiseControl.NET & batch's %ERRORLEVEL% CruiseControl.NET & batch's %ERRORLEVEL% Reviewed by Ran Davidovitz on 2:04 PM Rating: 5

4 comments:

Anonymous said...

Hi!
I'm experiencing exact opposite result with CruiseControl.Net.
Here's my batch file...
cd NotExistDir
ECHO ErrorCode = %ERRORLEVEL% Exit /B %ERRORLEVEL%
When I use "Exit /B %ERRORLEVEL%", CC always displays "SUCCESS".
When I use only "Exit", CC displays "FAILURE"
I'm wondering what could be the reason. Any comment?

Ran Davidovitz said...

weird, did you check the output to see what is the actual error code?

Anonymous said...

Actual error code was 1. I tried "Exit /B 1" also, but that doesn't work either. Only "Exit" worked. Very weird...

Anonymous said...

It is excactly what I was looking for. Thanks a lot, that was very useful.

Powered by Blogger.