我正在尝试在 Jenkins groovy shell 脚本中添加参数,然后想知道是否可以像这样嵌套使用 groovy 字符串插值。
node{
def A = 'C'
def B = 'D'
def CD = 'Value what I want'
sh "echo ${${A}${B}}"
}
Run Code Online (Sandbox Code Playgroud)
那么我所期待的就是这样;
'Value what I want'
Run Code Online (Sandbox Code Playgroud)
就像我一样;
sh "echo ${CD}"
Run Code Online (Sandbox Code Playgroud)
但是它给出了一些错误,即在步骤 [...] 中找不到 $
不可能吗?
像这样?
\n\nimport groovy.text.GStringTemplateEngine\n\n// processes a string in "GString" format against the bindings \ndef postProcess(str, Map bindings) {\n new GStringTemplateEngine().createTemplate(str).make(bindings).toString()\n}\n\nnode{\n\n def A = \'C\'\n def B = \'D\'\n\n def bindings = [\n CD: \'Value what I want\'\n ]\n\n // so this builds the "template" echo ${CD}\n def template = "echo \\${${"${A}${B}"}}"\xe2\x80\x8b\n // post-process to get: echo Value what I want\n def command = postProcess(template, bindings)\n\n sh command\n} \nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
3120 次 |
| 最近记录: |