从 Jenkins 管道中的 POM 中提取版本 ID [英] Extract version ID from POM in a Jenkins pipeline
问题描述
我已经创建了一个管道并使用了嵌入式 groovy 管道脚本定义,但似乎无法从 POM 中获取项目的版本 ID.我试过这个在 groovy 控制台中工作但在 Jenkins 构建管道脚本中:
I've created a pipeline and using the embedded groovy pipeline script definition and can't seem to get the version ID of the project from the POM. I tried this which works in a groovy console but on in the Jenkins build pipeline script:
def project = new XmlSlurper().parse(new File("pom.xml"))
def pomv = project.version.toString()
根据文档 Jenkins 有一个 $POM_VERSION
但是当我将它分配给一个变量并将其回显时,该值中没有任何内容.
According to the documentation Jenkins has a $POM_VERSION
but the value doesn't have anything in it when I assign it to a variable and echo it out.
def pomv = "$POM_VERSION"
或
def pomv = '$POM_VERSION"
推荐答案
使用 readMavenPom
像这样:
Use readMavenPom
like this:
pom = readMavenPom file: 'pom.xml'
pom.version
有关属性(如以上版本).
See Model reference for properties (like the above version).
为此,必须安装 Pipeline Utility Steps插件
这篇关于从 Jenkins 管道中的 POM 中提取版本 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!