Reputation: 4188
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...
Upvotes: 1
Views: 262
Reputation: 30432
You can use PowerShell to retrieve the number from variable $(build.sourcesdirectory) and pass the value to a new variable.
$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.
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:
Upvotes: 2