1

I typically tell TFS what folder to use via $(build.sourcesdirectory) which translates into C:\Builds\1\s .

However, I need to repack the deployment zip, so I had to add Content\C_C\Builds\myproj\1\s to my CI.

This isn't very good as the 1 can change due to dev ops work.

Is there a variable or technique I can use to replace the 1 with a variable?

I tried $(Agent.Id) with no luck...

RandomUs1r
  • 4,010
  • 1
  • 24
  • 44

1 Answers1

2

You can use PowerShell to retrieve the number from variable $(build.sourcesdirectory) and pass the value to a new variable.

Dynamically get the number Sample:

$string = "$env:BUILD_SOURCESDIRECTORY"
#$string = "E:\andyli-v\01Agent\_work\6\s" (The length is 29, the number '6' in the string is the 27th character, So get the substring as (26,1) means get one character behind the 26th character)
$parameter = $string.Substring(26, 1)
Write-Host "BUILD_SOURCESDIRECTORY is :" $string
Write-Host "The String length is : "$string.Length
Write-Host "The number is : "$parameter

You can use $parameter directly to get the number if do actions within the same script.

Set a variable :

If you want a variable, you can set it via PS :

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

You can reference there articles to set the variable:

enter image description here

Andy Li-MSFT
  • 28,712
  • 2
  • 33
  • 55
  • that's not a work around, is a solution. Using the word work around implies that there is something fundamentally wrong with product implementation that we need to work around. In this case that is not true, so you have proposed a solution to the problem, not a work around. – MrHinsh - Martin Hinshelwood Aug 01 '17 at 06:11
  • @RandomUs1r Have you resolved the issue by this solution? Any update? – Andy Li-MSFT Aug 03 '17 at 07:46