2

We have a version number which is retrieved from a file during the build and needs to be passed to the deployment script. What is the best way to do this in TFS 2017?

Right now, we are thinking of embedding this version number in the artifact file name and parsing it during deployment, which feels a bit clumsy.

BTW, is there a way to get the artifact file name easily? Looks like TFS already knows this as shown in the log below:

No path specified for search pattern: *.zip defaulting to: F:\TFS2017_Release_Agent\_work\r1\a
 
2017-12-08T16:38:36.8519067Z Searching for: *.zip under directory: F:\TFS2017_Release_Agent\_work\r1\a
 
2017-12-08T16:38:36.8519067Z Found: 1 files to extract:
 
2017-12-08T16:38:36.8519067Z F:\TFS2017_Release_Agent\_work\r1\a\ZFJ0_ServiceSearchPlusBuildDefn\BETALink.Service.SearchPlus\ZFJ0_BETALink10.4 DevOps_BETALink.Service.SearchPlus_1.0.0_886.zip
 
2017-12-08T16:38:36.8519067Z Creating destination folder: F:\TFS2017_Release_Agent\_work\r1\a\48
 
2017-12-08T16:38:36.8519067Z Extracting file: F:\TFS2017_Release_Agent\_work\r1\a\ZFJ0_ServiceSearchPlusBuildDefn\BETALink.Service.SearchPlus\ZFJ0_BETALink10.4 DevOps_BETALink.Service.SearchPlus_1.0.0_886.zip
 
2017-12-08T16:38:36.8519067Z [command]F:\TFS2017_Release_Agent\_work\_tasks\ExtractFiles_5e1e3830-fbfb-11e5-aab1-090c92bc4988\1.112.1\7zip\7z.exe x -oF:\TFS2017_Release_Agent\_work\r1\a\48 F:\TFS2017_Release_Agent\_work\r1\a\ZFJ0_ServiceSearchPlusBuildDefn\BETALink.Service.SearchPlus\ZFJ0_BETALink10.4 DevOps_BETALink.Service.SearchPlus_1.0.0_886.zip
 
2017-12-08T16:38:36.8987827Z 
janw
  • 8,758
  • 11
  • 40
  • 62
Jirong Hu
  • 2,315
  • 8
  • 40
  • 63
  • If the version number keeps changing, use it as your build number and get the build number via environment variable during the release would be an easy way to achieve the feature you want. – Eddie Chen - MSFT Dec 14 '17 at 07:05

1 Answers1

2

First, custom build variable couldn't be used directly in your release definition with TFS 2017.

There had also been a related user voice:

Project level build/release variables

https://visualstudio.uservoice.com/forums/330519-visual-studio-team-services/suggestions/14515326-project-level-build-release-variables#

As a workaround, you could use some 3-rd party extension such as Variable (de|re)Hydration Tasks that help you make use of your build variables in your Release workflows.

  • Variable Dehydration Task - During your build you can save the variables to a json file stored with your other build assets
  • Variable Rehydration Task - During your Release you can load the saved variables and gain access to them.

It does this by prefixes, so you can save/restore all default build variables that are prefixed with 'BUILD-', but if you prefix your own variables with i.e. 'ABC_' you can also save them from your build and restore them in your release.

Another way is do it through powershell scripts, how to please refer: TFS 2015 Release management access build variables


About build artifact name, there is not a related predefined system variable, it's just entered as an argument in Publish Build Artifacts task.

PatrickLu-MSFT
  • 49,478
  • 5
  • 35
  • 62