Cannot get teamcity to fail the build when msbuild fails.

939 views
Skip to first unread message

Stéphane Erbrech

unread,
Jul 12, 2012, 6:40:48 AM7/12/12
to psake...@googlegroups.com
Hi,

I set up teamcity to use psake using the psake.cmd

Here is my psake.cmd:

@echo off
if '%1'=='/?' goto help
if '%1'=='-help' goto help
if '%1'=='-h' goto help 

powershell -NoProfile -ExecutionPolicy Bypass -Command "& '%~dp0\Scripts\Build\psake.ps1' %*; if ($psake.build_success -eq $false) { exit 1 } else { exit 0 }"
goto :eof 
 
:help
powershell -NoProfile -ExecutionPolicy Bypass -Command "& '%~dp0\Scripts\Build\psake.ps1' -help"
 
my build tasks are described as follow : 
   
task CompileCommon {
exec { msbuild "$sln_file_common" /p:Configuration=$configuration }
}
task CompileClient {
exec { msbuild "$sln_file_client" /p:Configuration=$configuration }
}
task CompileServer {
exec { msbuild "$sln_file_server" /p:Configuration=$configuration }
}
task All -depends Clean, CompileCommon, CompileClient, CompileServer {
}

In TeamCity I have a Command line build step
 
Run : Executable with parameter
Command executable : psake.cmd
Command parameters : -t All

This was not failing the build, I added the following line in the psake.ps1 file as described in the github wiki
...
$psake.use_exit_on_error = $true
invoke-psake $buildFile $taskList $framework $docs $parameters $properties $initialization $nologo

This still doesn't fail the build.

There must be a simpler way to make psake "just work" on teamcity. What am I missing?

James Kovacs

unread,
Jul 12, 2012, 7:26:55 AM7/12/12
to psake...@googlegroups.com
Do you have msbuild wrapped in an "exec {}"? For example:

task build -depends clean {
  exec { msbuild <<params>> }
}

MSBuild is a plain old executable and doesn't throw exceptions like a PowerShell command would. Executables return their status through exit codes and PowerShell doesn't check exits codes. (Yes, this is very annoying.) So we have to wrap these calls in "exec {}", which checks the exit code and throws an exception on a non-zero exit code.

HTH,
James
--
James Kovacs, B.Sc., M.Sc.
http://jameskovacs.com
jko...@post.harvard.edu
@jameskovacs (Twitter)
403-397-3177 (mobile)
jameskovacs (Skype)


--
You received this message because you are subscribed to the Google Groups "psake-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/psake-users/-/oEGm-8wUe1MJ.
To post to this group, send email to psake...@googlegroups.com.
To unsubscribe from this group, send email to psake-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/psake-users?hl=en.

Stéphane Erbrech

unread,
Jul 12, 2012, 9:10:52 AM7/12/12
to psake...@googlegroups.com
I posted everything in my message, the msbuild calls are wrapped in exec. (see my task definitions)
To unsubscribe from this group, send email to psake-users+unsubscribe@googlegroups.com.

James Kovacs

unread,
Jul 12, 2012, 9:45:04 AM7/12/12
to psake...@googlegroups.com
Apologies. I should have read your message more closely. Which version of psake are you using? v4.1.0? I'll try debugging through this and want to make sure I have the right version.


James
--
James Kovacs, B.Sc., M.Sc.
http://jameskovacs.com
jko...@post.harvard.edu
@jameskovacs (Twitter)
403-397-3177 (mobile)
jameskovacs (Skype)


To view this discussion on the web visit https://groups.google.com/d/msg/psake-users/-/BfOJZUKSKiwJ.

To post to this group, send email to psake...@googlegroups.com.
To unsubscribe from this group, send email to psake-users...@googlegroups.com.

Stéphane Erbrech

unread,
Jul 12, 2012, 11:22:04 AM7/12/12
to psake...@googlegroups.com
yes, $psake.version = "4.1.0"

Thanks for your help

Stéphane Erbrech

unread,
Jul 17, 2012, 8:14:59 AM7/17/12
to psake...@googlegroups.com
I fixed my problem, Here is a blog post that explain my solution : Running directly the psake.ps1 using the powershell build step from teamcity.
There is also some extra tips that I found helpful about psake that aren't well documented.
Hopefully that can help someone.

Darren Haken

unread,
Jan 3, 2013, 3:20:40 PM1/3/13
to psake...@googlegroups.com
Can this be better documented on the wiki? I've lost around half a day of development trying to get this working.

yes, $psake.version = "4.1.0"

To unsubscribe from this group, send email to psake-users...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/psake-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "psake-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/psake-users/-/BfOJZUKSKiwJ.

To post to this group, send email to psake...@googlegroups.com.
To unsubscribe from this group, send email to psake-users...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages