Getting the build to fail
In my current configuration, I've got two steps. In the first step, I am building my .NET solution and running my Unit Test.
In the second step, I am deploying the files from the build. Now, what I would like to happen is not call the second step if the first step fail but I'm having problems with this.
In the first step, I am calling a batch file via the "Command line" runner in TeamCity 6.5.6. The content of that file is as follows:
------------------------
build\phantom\phantom.exe -f:build\BooScripts\build_CheckInScript.boo -a:buildEnvironment=%1
IF %ERRORLEVEL% == 0 EXIT /B 0 echo ##teamcity[buildStatus status='FAILURE' text='The build and run unit step failed'] EXIT /B 1
-----------------------
The first line calls a boo script which will build and run the unit tests. When, the unit tests pass, the second step in my configuration is called which is the desired behaviour but I get told that "The build and run unit step failed". How do I prevent that?
Now the second problem is that when the unit tests fail, the configuration still runs step 2 as shown by the following snippet of the log file indicates:
[Step 1/2] 1 Test(s) failed.
[16:01:27]: [Step 1/2] Target failed: Operation exited with exit code 1.
[16:01:27]: [Step 1/2] C:\TeamCity\buildAgent\work\55cbf3f731ca5225>IF 1 == 0 EXIT /B 0 echo
[16:01:27]: [Step 1/2] ##teamcity[buildStatus status='FAILURE' text='The build and run unit step failed']
[16:01:27]: [Step 1/2] EXIT /B 1
[16:01:27]: [Step 1/2] C:\TeamCity\buildAgent\work\55cbf3f731ca5225>rem did use the parameter below - and at some point should re-paramterise this again..
[16:01:27]: [Step 1/2] C:\TeamCity\buildAgent\work\55cbf3f731ca5225>rem -a:buildEnvironment=Dev
[16:01:27]: [Step 1/2] Process exited with code 0
[16:01:27]: Step 2/2: Command Line (10s)
[16:01:27]: [Step 2/2] Starting: C:\TeamCity\buildAgent\temp\agentTmp\custom_script8226453560404877895.cmd
[16:01:27]: [Step 1/2] Target failed: Operation exited with exit code 1.
[16:01:27]: [Step 1/2] C:\TeamCity\buildAgent\work\55cbf3f731ca5225>IF 1 == 0 EXIT /B 0 echo
[16:01:27]: [Step 1/2] ##teamcity[buildStatus status='FAILURE' text='The build and run unit step failed']
[16:01:27]: [Step 1/2] EXIT /B 1
[16:01:27]: [Step 1/2] C:\TeamCity\buildAgent\work\55cbf3f731ca5225>rem did use the parameter below - and at some point should re-paramterise this again..
[16:01:27]: [Step 1/2] C:\TeamCity\buildAgent\work\55cbf3f731ca5225>rem -a:buildEnvironment=Dev
[16:01:27]: [Step 1/2] Process exited with code 0
[16:01:27]: Step 2/2: Command Line (10s)
[16:01:27]: [Step 2/2] Starting: C:\TeamCity\buildAgent\temp\agentTmp\custom_script8226453560404877895.cmd
As you can see I have:
Target failed: Operation exited with exit code 1.
but I also have:
Process exited with code 0
What do I have to do to make the Process exit with an error code?
Please sign in to leave a comment.
Hello, David,
As to the first problem, you may add new lines to your script so that commands start on a new line
Moreover I advise you to add
command to the start of you script to avoid commad logging (which may be incorrectly interpreted by TeamCity) or use Custom script Command line runner setting.
As to the second problem I've created an issue http://youtrack.jetbrains.com/issue/TW-20481 in our public tracker, please vote for it and watch progress.
As a workaround try using EXIT 1 command instead of EXIT /B 1 if possible.
David,
Could you also please provide your OS version and more details about your build: please attach the full batch file content.
BTW:
[16:01:27]: [Step 1/2] EXIT /B 1
[16:01:27]: [Step 1/2] C:\TeamCity\buildAgent\work\55cbf3f731ca5225>rem did use the parameter below - and at some point should re-paramterise this again..
[16:01:27]: [Step 1/2] C:\TeamCity\buildAgent\work\55cbf3f731ca5225>rem -a:buildEnvironment=Dev
Seems that EXIT /B 1 doesn't cause the batch to exit at all.