Search code examples
tfstfsbuild

Read TFS build variables from file


Is it possible to read a file from the git source control and set values to TFS build variables so that we can use them in other steps?

We have a file with the version info and the branch (VER_TYPE=3 is DEV) that we use to set up assembly version together with the build number

VER_MAJOR=2018 VER_MINOR=1 VER_TYPE=3

Tks in advance!


Solution

  • It's possible to define or modify a variable from a script, use the task.setvariable logging command.

    Sets a variable in the variable service of taskcontext. The first task can set a variable, and following tasks are able to use the variable. The variable is exposed to the following tasks as an environment variable.

    When issecret is set to true, the value of the variable will be saved as secret and masked out from log. Secret variables are not passed into tasks as environment variables and must be passed as inputs.

    Examples:

    ##vso[task.setvariable variable=testvar;]testvalue
    ##vso[task.setvariable variable=testvar;issecret=true;]testvalue
    

    More details please refer Define and modify your variables in a script

    You can run a script on windows agent using either a Batch script task or PowerShell script task. You just need to read the specific file in source control, download it in the workspace on the build agent. Then read the file, a way using powershell for your reference: Read file line by line in PowerShell