Powershell Azure DevOps生成管道-无法访问脚本中的$(Build.BuildNumber)
在我的构建管道中,我正在执行以下操作:Powershell Azure DevOps生成管道-无法访问脚本中的$(Build.BuildNumber),powershell,azure-devops,azure-pipelines,Powershell,Azure Devops,Azure Pipelines,在我的构建管道中,我正在执行以下操作: 从Git还原 Powershell脚本-检索生成 编号并在…之前将其写入json文件 构建解决方案 归档文件 发布工件 在步骤2中,Powershell脚本非常简单: 定义的环境变量: Name: buildNumber Value: $(Build.BuildNumber) Name: rootPath Value:$(Build.ArtifactStagingDirectory) 代码: 由于某种原因,我的$buildNumber返回空值。$roo
Name: buildNumber Value: $(Build.BuildNumber)
Name: rootPath Value:$(Build.ArtifactStagingDirectory)
代码:
由于某种原因,我的$buildNumber返回空值。$rootPath正在运行。
我不能在生成步骤之外访问$(Build.BuildNumber)吗?生成编号格式在管道的选项中定义,在标记生成时可以正常工作,但我无法在powershell脚本中访问它
有什么想法吗?使用
$env:BUILD\u BUILDNUMBER
而不是$(…)
符号
请参阅。Ha,它起了作用!!非常感谢。澄清。。。。我删除了上面的环境变量,并在脚本中直接使用了这个符号:$env:BUILD\u BUILDNUMBER。再次感谢!
$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."
}