Search code examples
tfsazure-devopstfsbuildrelease-management

TFS. Pass variable from triggered build to next task in a release


I want to pass variable between release tasks. (from triggered build to script)

Files:

Script1: (saves a env variable)

Write-Output ("##vso[task.setvariable variable=MyVar;]$MyVarValue")

Script2: (prints the env variable value)

Write-host $env:MyVar

Script3: (same as Script2)

Write-host $env:MyVar

First approach: build

  • MyBuild:

    • Script1
    • Script2

This is working properly, the second script writes the value of $env:MyVar created in the first.

Second Approach: release - MyRelease:

  • Script1
  • Script2

Also works properly.

My problem comes when my release changes to:

  • MyRelease:
    • Triggered_build (MyBuild)
    • Script3

In that last case, the Script3 is not printing the $env:MyVar, so I guess that release uses a different environment than the used for the triggered build?

Is there a way to do something like that?


Solution

  • No way to do that directly with TFS.

    I have read about variable groups, but is not possible to set the variables dynamically in execution time with a script.

    The only solution found is using the plugin Variable (de|re)Hydration Tasks

    Solution from: Is possible to pass a variable from a Build to a Release in TFS 2017?