How to display the Project Version as Release name in Azure DevOps

时间:2019-05-31 11:53:11

标签: azure-devops azure-pipelines

I have the release version in pom.xml. For Example, xyz-0.0.1 is the version in my pom.xml. Azure Build creating the package.

I want to use the version xyz-0.0.1 as a release name in the release pipeline. How can I pass the version to release pipeline and set "Release name format" in options?

enter image description here

2 个答案:

答案 0 :(得分:2)

由于版本位于文件(pom.xml)中,因此无法将版本设置为“发布名称格式”,因此在发布期间需要从文件中提取版本并分配发布编号。

您可以使用PowerShell脚本(我写了这个概念,您需要了解如何确切地获取xml节点):

$file = Get-Content th/to/pom.xml
# Read the version with something like this:
# $version = Select-Xml -Content $file -XPath "//version"
# Then update the Release name:
Write-Host ##vso[release.updatereleasename]$version

enter image description here

答案 1 :(得分:0)

实际上,我们可以在这里使用maven帮助插件。

我正在这样做(使用bash步骤):

cd $(System.DefaultWorkingDirectory)/**[your project dir]**/
v=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
echo "##vso[release.updatereleasename]$v"

是的,发行版本应该是唯一的。要在脚本中更改它,我使用:

mvn versions:set -DnewVersion=[x.y.z]-RELEASE

或者您可以使用发布插件:

mvn --batch-mode release:update-versions -DdevelopmentVersion=[x.y.z]-RELEASE