引用带有凹槽的字符串中的变量
抱歉,如果还不够清晰。
我有以下groovy片段(来自詹金斯)
def jdk = jobConfig.java
jobConfig.env.JAVA_HOME="${tool '$jdk'}"
jobConfig.env.PATH="${env.JAVA_HOME}/bin:${env.PATH}"
如何在此行上的单个引号内替换$ jdk
变量的值?
jobConfig.env.JAVA_HOME="${tool '$jdk'}"
例如,这无问题。工具的用法还可以:
jobConfig.env.JAVA_HOME="${tool 'openjdk_11.0.14'}"
”的硬编码值设置为来自def jdk = jobconfig.java
的值
但是我想将“ OpenJDK_11.0.14 解决方案。
非常感谢
Sorry if it was not clear enough.
I have the following groovy snippet (from Jenkins)
def jdk = jobConfig.java
jobConfig.env.JAVA_HOME="${tool '$jdk'}"
jobConfig.env.PATH="${env.JAVA_HOME}/bin:${env.PATH}"
How can I substitute the value of $jdk
variable inside the single quotes on this line?
jobConfig.env.JAVA_HOME="${tool '$jdk'}"
For example, this works with no problems. The usage of tools is OK:
jobConfig.env.JAVA_HOME="${tool 'openjdk_11.0.14'}"
But I want to set the hardcoded value of 'openjdk_11.0.14' to the value coming from def jdk = jobConfig.java
I tried a few variations but couldn't find the solution.
Many thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
目前尚不清楚您的意思是什么,但是您拥有的是:
这是错误的,但要解决如何处理单个引号,其中1个问题是您已经嵌套了
$ 将混淆情况。
如果您试图将
jdk
的值与单样相关联,则可以做到这一点:请注意,引号不在
{}
表达式之外。一个单独的问题是您在该表达式中使用
工具
,但是上面说明了如何用单引号处理jdk
的价值。编辑
这个问题不清楚,但也许您想做这样的事情:
It isn't clear what you mean by that but what you have is this:
There are a few things wrong with that but to address how to deal with the single quotes, 1 of the issues is you have nested
$
which is going to confuse the situation.if you are trying to surround the value of
jdk
with single quotes, you can do this:Note that the quotes are outside of the
{}
expression.A separate issue is your use of
tool
in that expression, but the above explains how to deal with surrounding the value ofjdk
with single quotes.EDIT
The question isn't clear but maybe you are wanting to do something like this: