Monday, July 30, 2012

Running Powershell files from TeamCity

I've come across an amazingly easy way to get past the issue where TeamCity balks at executing powershell scripts. By default, on a brand new server TeamCity will not have access to execute powershell scripts as files, instead throwing an error message such as
zzz cannot be loaded because the execution of scripts is disabled on this system. Please see "get-help about_signing" for more details.
To get around it, the traditional way is to call Set-ExecutionPolicy RemoteSigned, but that can be difficult too, since you need to set it for the same user and architecture (x86 or x64) that TeamCity is running under. Rather then mess with that, Powershell's command line offers a five-second workaround:

-ExecutionPolicy ByPass

In the teamcity powershell build step, just add -ExecutionPolicy ByPass to the command line arguments, and you will be able to execute ps1 files to your heart's content.

1 comment :

  1. Hi, I am trying to call a VBS file from Team City, below is the configuration..
    Script : File
    Script File: Test.PS1
    Script Execution Mode: Put script into powershell stdin with "-command-" arguments

    But getting the error like:
    Cannot start build runner: Cannot run process C:\WINDOWS\sysnative\cmd.exe /c C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe -NonInteractive -ExecutionPolicy ByPass -Command - < C:\BuildAgent\work\2d7908fc7e0f07c9\Test.PS1 : file not found

    Thanks,

    ReplyDelete