【发布时间】:2021-10-01 07:03:33
【问题描述】:
我在 Azure Devops Server 2020 的管道中的作业中有一个 Powershell 任务。这是 powershell 的一部分:
$xml = [xml](Get-Content $configPath)
Write-Output "Iterating over appSettings"
ForEach($add in $xml.configuration.appSettings.add)
{
#Write-Output "Processing AppSetting key $($add.key)"
$SecretVarKey = "MAPPED_"+$add.key
Write-Output $SecretVarKey
$matchingEnvVar = [Environment]::GetEnvironmentVariable($SecretVarKey)
if($matchingEnvVar)
{
Write-Output "Found matching environment variable for key: $($add.key)"
Write-Output "Replacing value $($add.value) with $matchingEnvVar"
$add.value = $matchingEnvVar
}
}
这在任务中工作得很好——我的构建正在做我想做的事。但是当我查看 YAML 时,我会看到这样的 cmets:
#Your build pipeline references an undefined variable named ‘$add.key’. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab. See https://go.microsoft.com/fwlink/?linkid=865972
同样,这不会干扰脚本的执行。
但是,现在我想将此任务提取到一个任务组中。当我这样做时,无害的错误检测现在是一个问题,因为它坚持这些是新参数:
我可以做些什么来改变我的 Powershell 脚本,使它们不被认为是参数?
【问题讨论】:
标签: powershell azure-pipelines azure-devops-server-2020