我正尝试在Jenkinsfile中使用这个maven命令
mvn -q -Dexec.executable=echo -Dexec.args='${project.version}' --non-recursive exec:exec我将这个命令放在jenkinsfile的一个变量中,以便以后以这种方式使用它
def myCommand = 'mvn -q -Dexec.executable=echo -Dexec.args=\"${project.version}\" --non-recursive exec:exec'..。
def version = sh(${myCommand})我的问题是Jenkins不能正确地转义我的'${project.version}‘并输出java.lang.NoSuchMethodError: No such DSL method '$' found among steps
如何正确地将'${project.version}‘作为字符串包含在我的命令变量中?
发布于 2019-03-15 21:35:12
groovy中的单引号有一个问题-它不能替换变量。这应该是可行的:
def myCommand = "mvn -q -Dexec.executable=echo -Dexec.args='${project.version}' --non-recursive exec:exec"更多引用:What's the difference of strings within single or double quotes in groovy?
发布于 2019-03-15 23:00:45
只需将单引号替换为双引号:
def myCommand = "mvn -q -Dexec.executable=echo -Dexec.args=\"${project.version}\" --non-recursive exec:exec"https://stackoverflow.com/questions/55183432
复制相似问题