0

consider the following in my powershell step:

-source "c:\builds\$(Build.BuildNumber).zip"

result is "c:\builds\20171005.1.zip"

If I try and set the following in the configuration tab of my release variables of release like this Name=MyBuildNumber Value=$(Build.BuildNumber)

If I change my poweshell to look like this

-source "c:\builds\$(MyBuildNumber).zip"

result is "c:\builds\$(Build.BuildNumber).zip"

What am I a doing wrong here? I have tried a few different flavours of stored variables all with the same effect. Could really use some advice.

---------AS PER ANDY-MSFT---- I can confirm I am using Version 14.102.25423.0. I installed the variable extension pack.. no difference. The logs show the literal output. I am pretty sure I am using the exact same setup you are. Please check the screenshot of my definition variable and powershell syntax. TFS 2015 setup

macm
  • 544
  • 7
  • 21
  • You mention you've added my VSTS Variable Tasks, but did you add the Expand Variables task to your workflow prior to accessing the variable? You need to add this at every stage and if you're using multiple agents, you need to add the expand task to every agent scope. – jessehouwing Oct 09 '17 at 10:15
  • 1
    I was able to solve my problems by adding the expand variables task to my workflow. I didn't understand that was how this extension worked. For anyone else who gets hung up... download and install the extension. once installed goto your build or release definition and add expand variables task to your workflow. Works after that. – macm Oct 09 '17 at 16:36

1 Answers1

1

What's the exact version of TFS 2015 and the anent version do you use?

I tested on TFS 2015 Update4 (Version 14.114.26403.0, Agent.Version:1.95.4), everything works as expected.

So, please check What version of Team Foundation Server do you have, if you are using earlier version, you can try to upgrade to Update4 or later version, then try it again.

Besides, if you still want to keep your current version, you can use the VSTS Variable Tasks extension: Variable Toolbox to expand the build/release variables. (And the source code here for your reference.)

When you define a variable in the Variables screen and use other variables as value, they won't be expanded (as you may have expected). Instead the literal text is passed to the tasks in the workflow. Without this little task the following configuration won't work:

Variable              Value
Build.DropLocation    \\share\drops\$(Build.DefinitionName)\$(Build.BuildNumber)

By adding the Expand variable(s) task to the top of your workflow, it will take care of the expansion, so any task below it will receive the value you're after.

PS: The new agent (version 2.x) auto-expands variables now.

And this similar thread for your reference: TFS 2015 Can build variables access other build variables?


UPDATE:

Based on your TFS version, it should be TFS 2015 update3 (You can upgrade to Update4 or later version if that's an option, also upgrade the build Agent accordingly). To check the agent version : Go Manager Server (gear icon) >> AgentPool >> Select a pool >> select an agent >> Switch to Capabilities, you will see the agent version in that page.

enter image description here

Andy Li-MSFT
  • 28,712
  • 2
  • 33
  • 55
  • I updated my question above. Still can't get it to work. Unsure how to check agent version. – macm Oct 06 '17 at 16:24
  • @macm Based on your TFS version, it should be TFS 2015 update3. To check the agent version : Go Manager Server (gear icon) >> AgentPool >> Select a pool >> select an agent >> Switch to Capabilities, you will see the agent version in that page. – Andy Li-MSFT Oct 09 '17 at 09:53
  • +1 for mentioning my VSTS Variable tasks ;). There are a few issues with the 2015 agents that haven't been fixed, This concerns variable setting from tasks, so you may be bitten by this: https://github.com/Microsoft/vsts-agent/issues/177 – jessehouwing Oct 09 '17 at 10:20
  • Upgrading to Update 4 and switching to the 2.x agents is probably a good idea anyway (given that only the latest update version is supported), plus, it's time to start thinking about upgrading to 2017 or event 2018 (which seems on eminent release). – jessehouwing Oct 09 '17 at 10:22
  • Oh man... I completely and totally missed the boat on adding the expand variables task to my workflow. I was I guess just under the impression I needed to add the extension and it would just operate under the covers. I had no idea that in order to use the extension I would need to add it to workflow. Thanks for your help guys. – macm Oct 09 '17 at 16:33
  • You're welcome :). If you are happy with the functionality, I'd love a review. This has been developed in spare time and it helps others find it as well. – jessehouwing Oct 09 '17 at 17:54
  • Hey Jesse or Andy... I still can't get this release to work correctly. Upgraded TFS to Version 14.114.26403.0 / / Agent 1.95.4 . – macm Oct 10 '17 at 19:04
  • Hey Jesse or Andy... I still can't get this release to work correctly. Upgraded TFS to Version 14.114.26403.0 / / Agent 1.95.4. I am trying to get my artifact.releases.artifactAlias.buildnumber in my variables. Tried: $(Release.Artifacts.PROD - MyProject - Git.BuildNumber) $(Release.Artifacts.{PROD - MyProject - Git}.BuildNumber) $(Release.Artifacts.[PROD - MyProject - Git].BuildNumber) all within definition variables. Added ExpandedVariables to workflow. same result. https://learn.microsoft.com/en-us/vsts/build-release/concepts/definitions/release/variables?tabs=batch – macm Oct 10 '17 at 19:10