【发布时间】:2021-05-13 19:01:17
【问题描述】:
我需要创建以下 json 结构并使用 Azure Pipelines 将其包含在我的 .NET 应用程序中,但我不清楚如何执行此操作。
{
"buildNumber":"$(Build.BuildNumber)",
"buildId":"$(Build.BuildId)",
"branchName":"$(Build.SourceBranchName)",
"commitHash":"$(Build.SourceVersion)"
}
我尝试过简单地使用命令行将信息回显到文件中,但我不确定发布步骤获取该信息所需的路径。
现在我正在尝试一个 powershell 任务:
- task: PowerShell@2
inputs:
targetType: 'inline'
script: |
# Write your PowerShell commands here.
new-item -itemtype file -path $(Build.SourcesDirectory)/MyFirstExperiment -name "buildinfo.json" -force -value '{
\"buildNumber\":\"$(Build.BuildNumber)\",
\"buildId\":\"$(Build.BuildId)\",
\"branchName\":\"$(Build.SourceBranchName)\",
\"commitHash\":\"$(Build.SourceVersion)\"
}'
我在创建文件的任务期间看到了输出,但我仍然必须遗漏一些明显的东西,因为它没有出现在管道稍后的构建/发布中。
我应该检查什么?
我强烈怀疑我遗漏了一些非常明显的东西,因为在谷歌搜索“azure pipeline create file”时没有很多结果
提前谢谢你!
【问题讨论】:
-
要获得
$(Build.SourceVersion)的短git commit hash,请查看this post。它将短哈希(如提交历史中所示)保存到变量$(short_hash),您可以将其包含到您的文件中。
标签: .net azure powershell azure-devops azure-pipelines