0

So I defined a process template that accepts a String array called BuildDefinitionList in my Build Definition. I then call a powershell script. What I want to do is retrieve the array of type String. How do I achieve this from my powershell script?

Update:

I've modified the process template to have a InvokeProcess activity with a script path argument and a script arguments argument. In order to customize my definition, I've used the following as a guidance here.

I have a process parameter called Script which has the path to the powershell script I have another process parameter called ScriptArguments which has the following.

builds `"Test 1`", `"Test 2`", `"Test 3`", `"Test 4`"

My script accepts or is looking for a String array

[cmdletbinding()]
Param(
    [Parameter(Mandatory=$false,
                       ValueFromPipeline=$true,          
             ValueFromPipelineByPropertyName=$true)]
    $builds
)

When I run my build, I get the following error

A positional parameter cannot be found that accepts
 argument 'Test 1'.

1 Answer 1

-1

You create a parameter, and specify the type of [String[]] for it.

Param(
[String[]]$SomeStrings
)
ForEach($String in $SomeStrings){
    Do stuff!
}

Then just pass the array to the script when you call it.

Sign up to request clarification or add additional context in comments.

5 Comments

I don't want to do this because I need to create a standard for multiple build definitions. Each build definition will call into the same script and pass a String array. This is why I had created a build process parameter with the name being 'BuildDefinitionList'
I'm not following. I use PowerShell from a customized team build workflow. I use the InvokeProcess activity to fire up PowerShell.exe "out of process". The PowerShell session doesn't have any visibility to the team build object model so you need to pass in the array of strings as a parameter to your script. BTW if each build def "will call into the same script and pass a String array" and the script accepts a string array as a parameter, I'm not seeing what the problem is?
My problem is that I have a build process parameter which is of type String[]. this is where the person can choose a number or parameters to pass. And my build process parameter to run the script only accepts a string and it runs the script I provide. If I add arguments to that... I get a cannot find file error
So instead of marking down my answer maybe you should have posted your actual problem: How do I pass arguments to a script when calling it from a TFS build process parameter?
I would have to change the question completely. My original question was about passing build process parameters to a script. I know how to handle parameters in a powershell script. It was just irrelevant to the question. But if I have an InvokeProcess process in my build workflow, then How would I call my script and pass an array of Strings?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.