Skip to content

How can I integrate psake with Team City?

Mark Ingalls edited this page May 7, 2016 · 12 revisions

PowerShell runner

TeamCity 6.5 includes a bundled PowerShell runner.

If you are using a previous version of TeamCity, you may use the PowerShell runner plug-in; you can download the plug-in’s binaries here. See Installing Additional Plugins for general help on installing plug-ins for TeamCity.

Setup

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 & .\psake.ps1 to run default build
  5. Set additional command line parameters -NoProfile -ExecutionPolicy Unrestricted

Now you are ready.

Parameters

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 commas:

& .\psake.ps1 -parameters @{build_number=%build.number%,personal_build=%build.is.personal%}

If you are using PowerShell v3.0 or greater, you can get all of the TeamCity parameters into a hash with the following code in your .ps1 file:

$TCParams = ConvertFrom-StringData (Get-Content $env:TEAMCITY_BUILD_PROPERTIES_FILE -Raw);

After this code executes, you can access any TeamCity parameter as $TCParams['parameter.name'] e.g. $TCParams['build.number']

Messages

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 $($script:context.Peek().currentTaskName)"
}
Clone this wiki locally