Reputation: 2887
I have issues with accessing build variables from powershell script for example I want to access Agent.BuildDirectory. I tried:
$Build.SourcesDirectory
$(Build.SourcesDirectory)
none works.
I know that I can use $Env:TF_BUILD_SOURCESDIRECTORY but not all variables are available this way.
Do you have any suggestions ?
Upvotes: 1
Views: 2658
Reputation: 1100
So this is TFS 2017 Update 3. You should be able to do what you are trying to do. Where are you trying to use the variables, as parameter in the build or actually inside a PowerShell script? Those variable can be used as parameters and will be substituted at run time by the agent and passed to scripts, but if you are trying to access them inside a script like $(...) it will not work. You do need to use $env:VARIABLE. All variables in the variables section get converted to environment variables with their name at runtime. So for example if you are running an inline PowerShell like the image bellow, you can use $(..)
or if you want to pass parameters to the a PowerShell script you can also.
But from inside a script you cannot.
Upvotes: 3
Reputation: 31023
You should use $(Agent.BuildDirectory)
not $(Agent.SourcesDirectory)
. Check Agent variables from the link below:
Update: Adding a screenshot:
Upvotes: 1