【发布时间】:2021-07-16 17:20:37
【问题描述】:
我在 AzureDevOps 中有一个具有以下阶段的管道:
- Build:构建和生产一些 nugets(使用 cake build)。 nuget 包含用于某些设置的标记化 web.config,例如
"value=#{tokenName}"。 - 部署到环境 X:只需要替换 nuget 中 web.config 中的令牌并将其推送到 nuget 存储库。 (这适用于不同的环境)。
我只是想知道一个简单的方法来完成这项工作。
我知道 AzureDevOps 任务“替换令牌”可以实现这种替换,但这需要解包所有 nuget,替换并再次打包。对于大型 nuget,这是一项耗时的任务。
我想如果我只是从 nuget 解压缩匹配的 .config 文件,转换它们然后再次打包这些文件,这会更快。这将非常快。 问题是,在这种情况下,需要在 azuredevops 变量组中的值替换令牌的情况下在 powershell 中完成工作。
如果我有一个名为“Dev”的变量组和一个名为“IdentityService.BaseUrl”的变量
我在 powershell 中试过这样:
$content = "Example file string with token #{IdentityService.BaseUrl} end"
$variableName = [Regex]::Matches($content, '(?<=#{)(.*?)(?=})') | Select -ExpandProperty Value
# variableName is now "IdentityService.BaseUrl"
Write-Host "Value of $variableName is $($variableName)"
# This will print: Value of IdentityService.BaseUrl is IdentityService.BaseUrl
# I need to print the name of the variable and the variable value from the azureDevOpsGroup
有什么想法吗?
【问题讨论】: