Rob Bowman
Rob Bowman

Reputation: 8741

TFSBuild to include an array in parameters to powershell

I have a TFS 2010 build which calls a powershell script for deployment. I've defined several arguments for the build script and these have worked great. They are used by the build and also included in the arguments that are passed into Powershell via the Arguments property of the InvokeProcess control.

I now have a requirement for the powershell script to deploy to a variable number of servers, so I'd like to pass the server ID's in on the argument list from TFS.

In the build definition, I have declared a new argument called TargetServers of type string[]. I have populated this from the Build Process Parameters dialog prior to executing a build.

I have set the FileName property of the InvokeProcess control to "Powershell", and the Arguments property as follows:

String.Format(" ""& '{0}' '{1}' '{2}' '{3}' '{4}' '{5}' '{6}' '{7}' '{8}' '{9}' "" ", DeploymentScriptFileName, IO.Path.GetDirectoryName(DeploymentScriptFileName), "ExecuteBizTalkAppMSI.ps1", MSIFileName, BTDFFilename, TargetServerPath, TargetServers, ServerDeploymentFolder, InstallFolder, HostInstanceFilter, ApplicationName) 

My problem is that the TargetServers argument being passed to Powershell is simply System.String[].

From the build log I can see the following output of the Invoke Process control:

Powershell  "& 'C:\Builds\3\x.Int.MIS.Deployment\CopyDeployScriptThenExecute.ps1'
'C:\Builds\3\\x.Int.MIS.Deployment' 'ExecuteBizTalkAppMSI.ps1'
 'x.Int.MIS-3.0.0.msi' 'x.Int.MIS.Deployment.btdfproj'
'\\d-vasbiz01\BizTalkDeployment' 'System.String[]' 'c:\BizTalkDeployment'
'c:\Program Files (x86)\x.Int.MIS for BizTalk 2010\3.0' 'BTSSvc*MIS*' " 

Can anyone please advise how to pass the array?

Upvotes: 0

Views: 1337

Answers (1)

Joey
Joey

Reputation: 354834

As strings delimited by commas:

PS> function foo([string[]]$x){$x}
PS> foo a,2,3
a
2
3

If you want, you can put quotes around each individual item but you don't need to unless they contain spaces or other characters reserved for the syntax.

Upvotes: 1

Related Questions