How can I integrate psake with Team City?

Gary Ewan Park edited this page Mar 20, 2016 · 20 revisions

This wiki is now deprecated. Please see the latest documentation here

PowerShell runner or Command Line runner

TeamCity 6.5 has a bundled PowerShell runner, which can be used to run psake builds. For older versions of TeamCity, the PowerShell runner plug-in will do the job; you can download the plug-in’s binaries here. See Installing Additional Plugins for general help on installing plug-ins for TeamCity.

Alternatively you can just run PowerShell.exe from Command Line Runner and then run psake. See example in psake.cmd.

Setup of PowerShell runner

Add a new build step and select PowerShell runner.

  1. Set your run mode (x86 or x64)
  2. Set your working directory (typically the directory where your build scripts are located)
  3. Select Source code mode in Script input
  4. Insert into Script Source
    Import-Module 'PATH_TO_PSAKE_ROOT_FOLDER\psake.psm1'
    Invoke-psake .\PSAKE_BUILD_FILENAME.ps1 RunTests 
  5. For 4.0.0: Make sure you have added $psake.use_exit_on_error = $true somewhere before the Invoke-psake call (e.g., amend the psake.ps1 file)
  6. For 4.0.1 unofficial realease on NuGet no additional steps are required
  7. For current development version append to & .\psake.ps1 also ; if ($psake.build_success -eq $false) { exit 1 } else { exit 0 }" to notify TeamCity about build failure

Now you are ready.


If you need parameterize your build script, you can use the predefined TeamCity parameters and variables. Pass in the parameters as a hash table using the following syntax:

& .\psake.ps1 -parameters @{build_number=%build.number%}

You can pass multiple parameters by separating them with semicolons:

& .\psake.ps1 -parameters @{build_number=%build.number%;}


There is a TeamCity module included in the Psake Contrib project which provides tighter integration with TeamCity. For example, you can report the currently-executing task to TeamCity by inserting the following lines into your build script (after the Properties section):

Include .\teamcity.psm1
TaskSetup {
    TeamCity-ReportBuildProgress "Running task $($psake.context.Peek().currentTaskName)"
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.