【发布时间】:2020-10-20 09:47:52
【问题描述】:
我正在 Azure 构建管道中创建新的 VSTS/TFS 扩展。 在该扩展中,一个字段接受文件路径,它是可选字段。 在 powershell 脚本中,我想验证该字段,如果没有提供输入,那么我必须忽略,否则我必须检查输入是否为 .config 文件的路径。
$ConfigFileName = Get-VstsInput -Name 'ConfigFilePath'
if (!(Test-Path $ConfigFileName))
{
Write-Host "Configuration file doesn't exist."
"##vso[task.complete result=Failed]"
throw "Configuration file doesn't exist."
}
if([IO.Path]::GetExtension($ConfigFileName) -ne '.config')
{
Write-Host "Invalid configuration file.File type must be of .config"
"##vso[task.complete result=Failed]"
throw "Invalid configuration file.File type must be of .config"
}
我已经像上面那样进行了验证,但是当用户没有提供任何输入时,$ConfigFileName 变量也填充了映射路径,即 $ 值。 如何检查提供给该字段的输入是否为空?
【问题讨论】:
标签: azure-pipelines-release-pipeline azure-pipelines-build-task build-pipeline