我通常告诉 TFS 使用哪个文件夹,通过$(build.sourcesdirectory)
哪个文件夹转换为 C:\Builds\1\s 。
但是,我需要重新打包部署 zip,所以我必须添加Content\C_C\Builds\myproj\1\s
到我的 CI。
这不是很好,因为 1 可能会由于开发操作工作而改变。
我可以使用变量或技术将 1 替换为变量吗?
我试过 $(Agent.Id) 没有运气......
我通常告诉 TFS 使用哪个文件夹,通过$(build.sourcesdirectory)
哪个文件夹转换为 C:\Builds\1\s 。
但是,我需要重新打包部署 zip,所以我必须添加Content\C_C\Builds\myproj\1\s
到我的 CI。
这不是很好,因为 1 可能会由于开发操作工作而改变。
我可以使用变量或技术将 1 替换为变量吗?
我试过 $(Agent.Id) 没有运气......
您可以使用 PowerShell 从变量 $(build.sourcesdirectory) 中检索数字并将该值传递给新变量。
$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
如果在同一脚本中执行操作,您可以直接使用$parameter获取数字。
如果你想要一个变量,你可以通过 PS 设置它:
Write-Output ("##vso[task.setvariable variable=GetNumber;]$parameter")
您可以参考那里的文章来设置变量: