Powershell optional arguments

Is it possible to have some optional arguments with the Powershell Runner?   As an example, we have written a powershell script (Build-Databases.ps1) that restores a backup of our production databases, massages the data (updates email addresses to development email addresses, etc...), does a sql compare using Red Gate and some other stuff.

We have a convention we follow, and 90% of the time, we only need a single argument passed to our Build-Databases.ps1 script, the server name that we are deploying the database/scripts to.

However, we also have some additional argument overrides that allow you to be more verbose and specify options that we normally have defaults for.

I was attempting to use Build Parameters to pass into my powershell script, but it seemed like all or nothing.

Assume that 90% of the time we can call our script like this:

./Build-Databases.ps1 -Server "ServerA"

but sometimes we would like to call our script like this:

./Build-Databases.ps1 -Server "ServerA" -Option1 "Option1" -Option2 "Option2"

There isn't an easy way to handle the second scenario with TeamCity currently.   

It would be really great if the Powershell Runner could "opt-in" to Build Parameters if they have a value, or ignore them they have no value.   It seems like this would require some additional UI work to match the argument name with the argument value.   Any ideas on how I could accomplish this?

2 comments
Comment actions Permalink

It is possible now. To do it, please make the following:
- open build configuration
- create configuration parameter names 'option1' with value 'not-set'
- open powershell runner and add this property as argument to powershell, i.e. /option1=%option1%
- patch you .ps1 script to treat 'not-set' in the same way there is no /option1 argument


To start your script with custom parameters use Custom Run Dialog (click '...' on run button).
http://confluence.jetbrains.net/display/TCD65/Triggering+a+Custom+Build#TriggeringaCustomBuild-runCustomBuild

0
Comment actions Permalink

It does not work, I have the same problem. How can I deal with optional parameters?

0

Please sign in to leave a comment.