从 Jenkins 管道中的 POM 中提取版本 ID [英] Extract version ID from POM in a Jenkins pipeline

查看:46
本文介绍了从 Jenkins 管道中的 POM 中提取版本 ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个管道并使用了嵌入式 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆