我需要在文件中附加一个字符串。该字符串由一些前缀+变量组成。这是在使用Groovy语法的Jenkins管道中,因此读取变量值的唯一方法是使用多行双引号sh。
sh """
...some lines of code affecting the same scope...
echo "sdk.dir=${ANDROID_HOME}" > local.properties
...some lines of code affecting the same scope...
"""
实际:
WorkflowScript: 101: illegal string body character after dollar sign;
solution: either escape a literal dollar sign "\$5" or bracket the value expression "${5}" @ line 101, column 49.
echo "sdk.dir=${ANDROID_HOME}" > local
您是否尝试过用斜杠来使$符号转义,因为出现了错误?
另外,您使用的是相同的双引号,请像现在一样,尝试将“ sh”命令替换为三重单引号,并对外壳重定向使用双引号。
或者最后一个选择,您可以转义整个表达式:
\\“ 表现 \\”
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句