我正在尝试在Jenkinsfile中获取pom.xml版本,然后在shell脚本中使用该版本。当尝试使用pom.version
时,会出现异常bad substitution
。传递pom版本的正确语法是什么?
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。有必要重启詹金斯吗?
如果要替换${pom.version}
,则需要使用GString。您使用的三引号定义了一个不支持变量替换的多行Java字符串。您需要将'''
替换为"""
,以定义一个可以替换${WORKSPACE}
和${pom.version}
这两个变量的多行GString。