TeamCity and Powershell

Hi,

I currently have a Build Step that runs a powershell script. The powershell script has a number of teamcity build parameters passed to it e.g. $services = %deployment.services%. The powershell script is of type "Source Code" so the actual source code is contained within the Build Step. This runs fine just now. I have been trying to move this script into one of our Git repo's and change the Build Step to download and use that instead but it looks as though I can no longer reference in the build parameters in it. Is that the case?

I've also had problems try to run a particular cmdlet within the script. Is this actually possible?

Thanks
Colin

4 comments
Comment actions Permalink

Hey Colin,
My understanding is that if you have the script source in TeamCity it actually subsitutes the %variable.name% value into the physical source at build time. e.g.

$services = %deployment.services%
would become
$services = servicename

If you are now executing this as a file, I don't think that substitution will happen. This may depend on the "Script execution mode", however I believe that if you are now running this from a file you would need to pass the TeamCity parameters in from "Additional command line parameters" to the script. If you are using TeamCity 8.1.x you would need to click "Show advanced options" at the bottom of the Powershell build step configuration page to see this option.

Some variables are also available as environment variables.

Hope this helps :)

0
Comment actions Permalink

Hi Sean,

Thanks for that. Kind of what I suspected. I've reverted to using the source stored in TC for now but I'll give the additional parameters a go when I get a chance.

Cheers
Colin

0
Comment actions Permalink

No Worries :)

Did you want to put it into a Git repo just for versioning or to be shared around?

If you thinking of sharing it around have you looked into making it a Meta-Runner?

0
Comment actions Permalink

The powershell script lives in one of our git repo's. It's in there for versioning and also because we use bits of it and other scripts elsewhere. So I'd prefer to get it from there prior to doing the build.

Cheers
Colin

0

Please sign in to leave a comment.