TeamCity 8.0 Help

PowerShell

PowerShell build runner is designed specifically to run PowerShell scripts.

PowerShell Settings

Option

Description

Version

List of PowerShell versions, supported by TeamCity. Since 8.1 is passed to powershell.exe as -Version command line argument

Powershell run mode

Select the desired execution mode on a x64 machine.

Error Output

Specify, how error output is handled by the runner:

  • error: any output to stderr is handled as error

  • warning: default setting; any output to stderr is handled as warning

Working directory

Specify the path to the Build Working Directory.

Script

Select whether you want to enter the script right in TeamCity, or specify path to a script:

  • Script file: Enter path to Powershell file. It has to be relative to checkout directory.

  • Script source: Enter PowerShell script source. Note, that TeamCity references (build parameters and TeamCity system properties) will be replaced in the code.

Script execution mode

Specify the PowerShell script execution mode. By default, Powershell may not allow execution of arbitrary .ps1 files. TeamCity will try to supply the -ExecutionPolicy ByPass argument. If you've selected Execute .ps1 script from external file, your script should be signed or you should make PowerShell allow execution of arbitrary .ps1 files. If the execution policy doesn't allow running your scripts, select Put script into PowerShell stdin mode to avoid this issue.

Script arguments

Available if "Script execution mode" option is set to "Execute .ps1 script with the -File argument". Specify here arguments to be passed into PowerShell script.

Additional command line parameters

Specify parameters to be passed to powershell.exe.

Interaction with TeamCity

Attention must be paid, when using PowerShell to interact with TeamCity through service messages. Powershell tends to wrap strings written to console with commands like Write-Output, Write-Error and similar (see TW-15080). To avoid this behavior, either Write-Host command should be used, or buffer length should be adjusted manually:

function Set-PSConsole { if (Test-Path env:TEAMCITY_VERSION) { try { $rawUI = (Get-Host).UI.RawUI $m = $rawUI.MaxPhysicalWindowSize.Width $rawUI.BufferSize = New-Object Management.Automation.Host.Size ([Math]::max($m, 500), $rawUI.BufferSize.Height) $rawUI.WindowSize = New-Object Management.Automation.Host.Size ($m, $rawUI.WindowSize.Height) } catch {} } }

PowerShell support is implemented as an open-source plugin. For development links refer to the PowerShell.

Last modified: 20 April 2023