3

I am using Release Management 2015 and doing Agent deploys. I want to access the TFS Build Number and use it as part of my deployment. The RM documentation says that starting with RM 2013 U4, system variables are available for use. The documentation implies that they are available to any type of deployment, however, I've read that they are only available to vNext (agent-less) deployments.

Unfortunately, there are no examples to give any guidance on how to access them. Does anyone have an example of how to reference a System variable in a deployment template?

mcolegro
  • 559
  • 5
  • 18

2 Answers2

2

You can access the build number in a Component in an agent-based release template by referencing it as $(BuildNumber). You must pass $(BuildNumber) as a parameter to the component, which means defining a __Build Number__ parameter and passing the value in. Naturally, you must also be using a release template that is tied to a TFS build definition.

The user-definable system variables in Release Management are for vNext releases, not agent-based releases.

Daniel Mann
  • 57,011
  • 13
  • 100
  • 120
  • I tried constructing a component using the _XCopy Deployer_ as the tool and adding a configuration variable which I subsequently set to $(BuildNumber) in the template. What I got for the token was "$(BuildNumber)". Do I have to reference the System Variable in the arguments for the command in order to get the value? – mcolegro Oct 16 '15 at 15:15
  • @mcolegro I updated my answer for more clarity around the proper way to pass the `$(BuildNumber)` value. – Daniel Mann Oct 16 '15 at 15:24
  • Thanks. I'll give that a try. – mcolegro Oct 16 '15 at 15:34
  • Interestingly, if my Build Definition name contains a space, $(BuildNumber) shows only the first word. $(buildNumber) shows the second word. I changed my build definition names to not have spaces. – mcolegro Oct 23 '15 at 15:57
0

In your vNext Release Template add a Deploy Using PS/DSC action; set this action to execute a PowerShell script. In that script you have access to almost all system variables:

Write-Verbose "BuildNumber = $($BuildNumber)" -Verbose
ds19
  • 3,176
  • 15
  • 33
  • Thanks, but I'm not using vNext templates. Will this work with an Agent deploy? – mcolegro Oct 16 '15 at 12:13
  • The MSDN states that the system and the configuration variables are available only for vNext templates: https://msdn.microsoft.com/en-us/library/dn834972(v=vs.120).aspx. As mentioned here (http://stackoverflow.com/a/28681188/1225429) you can use $(PackageLocation) – ds19 Oct 16 '15 at 12:38