13

I am using default build template with TFS 2013, how i can access build parameters (for example, changeset number under build, build directory, source paths, tfs address, agent information...) from powershell script?

Example situation: I want to rewrite all assembly info version informations on Pre-Build script where last part of version number is changeset number, i can probably get changeset with tf.exe commands inside of script but i isn't only thing which i want to know from build agent during build.

I have tried run Get-Variable in script and write it to build but i haven't find any special variables inside of script.

Is there something i have missed or is it so that default build template simply does not pass any variables to powershell runtime during execution?

1 Answer 1

29

Figured it out.

Variables are automatically written as environment variables, dir env: showed me that tfs automatically create following variables:

 TF_BUILD                       True
 TF_BUILD_BINARIESDIRECTORY     C:\WP0\101\bin
 TF_BUILD_BUILDDEFINITIONNAME   TfsBuildTest2
 TF_BUILD_BUILDDIRECTORY        C:\WP0\101
 TF_BUILD_BUILDNUMBER           TfsBuildTest2_20140310.3
 TF_BUILD_BUILDREASON           Manual
 TF_BUILD_BUILDURI              vstfs:///Build/Build/6521
 TF_BUILD_DROPLOCATION
 TF_BUILD_SOURCEGETVERSION      C22404
 TF_BUILD_SOURCESDIRECTORY      C:\WP0\101\src
 TF_BUILD_TESTRESULTSDIRECTORY  C:\WP0\101\tst
 TFS_REG_CRED                   Build
Sign up to request clarification or add additional context in comments.

5 Comments

For what it's worth, these are documented here: msdn.microsoft.com/en-us/library/hh850448.aspx +1 for discovering TFS_REG_CRED, which isn't documented.
How did you actually declare these in your powershell script? Or did you pass them in as parameters from the build definition? e.g. for example $("TF_BUILD") or just TF_Build?
These are environment variables. In Powershell the syntax is $env:TF_BUILD_BUILDNUMBER
What if you create a new (custom) variable in the build template (like versionnumber for incrementing assemblyInfo.cls) how can you get that variable in the powershell script?
For the life of me I always get empty string for TF_BUILD_BUILDURI. I've created a variable and still nothing

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.