8

I am working on vNext builds TFS 2015. How can we pass a user defined variable from vNext build to power shell script? I am adding powershell script as a step in the build definition.

jessehouwing
  • 106,458
  • 22
  • 256
  • 341
CKS
  • 497
  • 3
  • 9
  • 16

2 Answers2

15

You can define build variables, then reference them in the PowerShell task under arguments. For example if my powershell script took a parameter called foo I could do this:

enter image description here enter image description here

Dylan Smith
  • 22,069
  • 2
  • 47
  • 62
  • Thanks Dylan for the answer. I tried above but it is not working for me. I am trying to do a simple robocopy and pass the folder name using the build arguments and build variables. it is not accepting the folder name : for ex robocopy C:\temp\abc\ C:\temp\xyz\$foldername\ I am passing $foldername through arguments and user variable...Am i doing something wrong? – CKS Nov 16 '15 at 16:33
  • I thought you said you are running a powershell script? did you write your powershell script to accept parameters? if not you need to do that first. – Dylan Smith Nov 16 '15 at 21:19
  • 1
    Thabnks Dylan, I added param ($foldername) and it started working. The script does what it is supposed to do, but the build is failing. There is no information in the logs as well and my definition has only one step Powershell. the only error message i get is : "Task PowerShell failed. This caused the job to fail. Look at the logs for the task for more details." – CKS Nov 18 '15 at 15:36
1

You Can access the V next user variables in power shell like below,

Example:

$env:foo

In your case it is,

blah.ps1 -foo $env:foo
Mukul Varshney
  • 3,131
  • 1
  • 12
  • 19