如何在jenkinsfile的shell命令中使用pom版本? [英] How to use pom version in shell command in jenkinsfile?
问题描述
我试图在Jenkinsfile中获取pom.xml版本,然后在shell脚本中使用该版本.
尝试使用pom.version
时,这会给出异常bad substitution
.传递pom版本的正确语法是什么?
I am trying to get pom.xml version within Jenkinsfile and then use that version in a shell script.
This gives the exception bad substitution
when trying to use pom.version
. What is the correct syntax to pass the pom version?
script {
def pom = readMavenPom file: 'pom.xml'
withCredentials(...) {
sh '''#!/bin/bash
cp "${WORKSPACE}/target/stats-${pom.version}-shaded.jar" /xyz
'''
}
}
我为readMavenPom
cmd安装了Pipeline Utility Steps
插件,但没有重新启动Jenkins.是否需要重新启动Jenkins?
I installed Pipeline Utility Steps
plugin for readMavenPom
cmd but didn't restart Jenkins. Is it necessary to restart Jenkins?
推荐答案
如果要替换${pom.version}
,则需要使用GString.您使用的三引号定义了不支持变量替换的多行Java字符串.您需要将'''
替换为"""
,以定义可以替换${WORKSPACE}
和${pom.version}
变量的多行GString.
If you want to substitute ${pom.version}
, you need to use GString. The triple-quote you used defines a multiline Java string that does not support variables substitution. You need to replace '''
with """
to define a multiline GString that can substitute both variables, ${WORKSPACE}
and ${pom.version}
.
这篇关于如何在jenkinsfile的shell命令中使用pom版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!