如何在Azure Pipelines YAML版本定义中接收修订 [英] How to receive Revision in Azure Pipelines YAML build definition
问题描述
我使用Azure Pipelines(Azure DevOps)创建了一个新版本,并且效果很好.
I created a new build with Azure Pipelines (Azure DevOps) and it worked really well.
通常,您使用$(Rev:.r)
在版本中获取修订.不幸的是,在构建步骤中似乎没有替换/设置该变量.唯一可以使用它的地方是YAML文档中的name:
属性.
Usually, you use $(Rev:.r)
to get the revision in the build. Unfortunately, it seems the variable isn't replaced/set in the build steps. The only place where you can use it is the name:
property in the YAML document.
现在,我将其设置为名称,然后将其提取到某些PowerShell中,如果可以通过环境变量获取它,则没有必要.
Now I set it in the name and extract it in some PowerShell, which isn't necessary if you can get it via an environment variable.
如何在新版本(YAML文档中name:
属性的外部)中获得修订版本(如$(Rev)
)?
How do I get the Revision (like $(Rev)
) in the new builds (outside of the name:
property in the YAML document)?
(在Docker内部在内部运行的Build Agents-但这不应该影响上面的内容)
(The Build Agents running on-premise, inside Docker - but this shouldn't affect the things above)
推荐答案
未经解析就无法获取版本号,它不会作为单独的字段存储在某个地方或环境变量中.
You can't get the revision number without parsing, it is not stored as a separate field somewhere or in an environment variable.
$(Rev:.r)
部分指示Azure DevOps提出使内部版本号唯一的第一个数字(并在该特定示例中,在其前面加一个点).
The $(Rev:.r)
portion instructs Azure DevOps to come up with the first number that makes the build number unique (and, in that specific example, put a dot in front of it).
就像您说的那样,唯一的方法是使用PowerShell脚本获取值:
Like you said, the only way is to use PowerShell script to get the value:
$buildNumber = $Env:BUILD_BUILDNUMBER
$revision= $buildNumber.Substring($buildNumber.LastIndexOf('.') + 1)
您可以安装获取修订版本扩展程序.
这篇关于如何在Azure Pipelines YAML版本定义中接收修订的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!