在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"
OR
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).
为此,必须安装管道实用程序步骤插件
这篇关于在Jenkins管道中从POM提取版本ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!