【发布时间】:2018-10-19 20:35:11
【问题描述】:
在我的构建管道中,我正在执行以下操作:
- 从 Git 恢复
- Powershell 脚本 - 检索构建 编号并将其写入 json 文件之前....
- 构建解决方案
- 存档文件
- 发布工件。
在第 2 步中,Powershell 脚本非常简单:
定义的环境变量:
Name: buildNumber Value: $(Build.BuildNumber)
Name: rootPath Value:$(Build.ArtifactStagingDirectory)
代码:
$theFile = Get-ChildItem -Path $rootPath -Recurse -Filter "host.json" | Select-Object -First 1
$propertyName = "BuildNumber"
if($theFile)
{
$json = Get-Content "$theFile" | Out-String | ConvertFrom-Json
if($json.$propertyName)
{
$json.$propertyName = $buildNumber
}else{
Add-Member -InputObject $json -MemberType NoteProperty -Name $propertyName -Value $buildNumber
}
$json | ConvertTo-Json -depth 100 | Out-File "$theFile"
}
else
{
Write-Warning "Found no files."
}
由于某种原因,我的 $buildNumber 返回 null。 $rootPath 正在工作。 我无法在构建步骤之外访问 $(Build.BuildNumber) 吗?内部版本号格式在管道的选项中定义,在标记构建时可以正常工作,但我无法在我的 powershell 脚本中访问它。
有什么想法吗?
【问题讨论】:
标签: powershell azure-devops azure-pipelines