2

In Team Foundation Server 2015 in build definition I use my custom variables defined on Variables tab. Is there any way to access them in PowerShell build step like predefined variables can be accessed e.g. "$env:BUILD_DEFINITIONNAME"? Thank you

1 Answer 1

4

[disclaimer: I work on the new build system]

I often advise folks to use the cmdline task or a cmd script to print out the variables (call set on windows, env on *nix). There's docs etc... but actually running it will show exactly what is really available.

Add cmdline task (in utility) with tool = cmd and arguments = /k set

Variables on the definitions variable tab should be available as environment variables upper cased

So:

my variable

Is available as the environment variable

MY VARIABLE

There is a current bug, it should be per spec MY_VARIABLE. On the xplat agent/shell script it's MY_VARIABLE

This makes it accessible to cmd, powershell, shell etc... scripts.

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

4 Comments

Thank you bryanmac, I should realize this. It's very useful method for many circumstances. The environment variable I've searched for is BUILD_DROPLOCATION, so it seems "BUILD_" prefix is used for custom build variables.
Nope - there's system and build variables that start with system.xxx and build.xxx - those are converted to envvar toUpper and space -> _. See msdn.microsoft.com/Library/vs/alm/Build/scripts/variables
vars on the def vars tab should just be capped and underscored (althought bug I mentioned above)
Note: There seems to be something special/magical (and undocumented) about a variable named “DropLocation”. It gets turned into the BUILD_DROPLOCATION environment variable, and you can’t use it as $(DropLocation) in the UI. You have to use it as $(Build.DropLocation). However, most custom variables don’t get the “Build.” prefix stuck on them (e.g., a ProductName variable can be used as $(ProductName) in the UI and as the PRODUCTNAME environment variable). I'm on 2015 Update 2, but I suspect @Michal ran into this special case even in RTM.

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.