Kic*_*Mhl 3 powershell azure-devops azure-pipelines
在我的构建管道中,我正在执行以下操作:
在步骤2中,Powershell脚本非常简单:
定义的环境变量:
Name: buildNumber Value: $(Build.BuildNumber)
Name: rootPath Value:$(Build.ArtifactStagingDirectory)
Run Code Online (Sandbox Code Playgroud)
码:
$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."
}
Run Code Online (Sandbox Code Playgroud)
由于某种原因,我的$ buildNumber返回空值。$ rootPath正在工作。我无法在构建步骤之外访问$(Build.BuildNumber)吗?内部版本号格式在“管道的选项”中定义,在标记内部版本时可以很好地工作,但是我无法在Powershell脚本中访问它。
有什么想法吗?
使用$env:BUILD_BUILDNUMBER
代替$(...)
符号。
请参阅文档中针对不同脚本类型的不同符号。
归档时间: |
|
查看次数: |
1371 次 |
最近记录: |