0

I have a script which takes arguments as

.\script1.ps1 -Arg1 "Argument 1" -Arg2 "Argument 2"

I have set the format for arguments in TFS as:

.\script.ps1 -Arg1 $($arg1) -Arg2 $($Arg2)

I get the following error when I try to pass just Arg2:

Missing an argument for parameter 'Arg1'. Specify a parameter of type 'System.String[]' and try again.

2
  • Inside the ps1 file, just change the param type to system.string like `[String]$param1' Commented Jun 19, 2017 at 7:39
  • Possibly a duplicate question for :stackoverflow.com/questions/36142045/… Which version of TFS? Commented Jun 19, 2017 at 8:13

1 Answer 1

1

According to your question, you are placing the arguments in variables. And I suspect that you just enter the value for $Arg2 variable when you try to pass just Arg2. In this scenario, the powershell script is run in the following format will the cause the error message you got since the Arg1 argument is empty:

.\script.ps1 -Arg1 -Arg2 Arg2Value

A workaround for this would be using variable to control the arguments directly. For example, add two variable in the build definition: Arg1 and Arg2 enter image description here

And in the PowerShell script task arguments, just enter: $(Arg1) $(Arg2) enter image description here

With this, you can simply set the Arg1 variable to empty when queue the build if you only want to pass Arg2.

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

Comments

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.