如何在 Jenkins Groovy 中的多行 shell 脚本中设置变量? [英] How to set variables in a multi-line shell script within Jenkins Groovy?

查看:118
本文介绍了如何在 Jenkins Groovy 中的多行 shell 脚本中设置变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我在 Jenkins 中有一个 Groovy 脚本,其中包含一个多行 shell 脚本.如何在该脚本中设置和使用变量?正常方式会报错:

sh """富='酒吧'回声 $foo"""

<块引用>

捕获:groovy.lang.MissingPropertyException:没有这样的属性:类的foo:groovy.lang.Binding

解决方案

需要改成三重单引号'''或者转义美元$

然后你将跳过给你这个问题的 groovy 模板

Suppose I have a Groovy script in Jenkins that contains a multi-line shell script. How can I set and use a variable within that script? The normal way produces an error:

sh """
    foo='bar'
    echo $foo
"""

Caught: groovy.lang.MissingPropertyException: No such property: foo for class: groovy.lang.Binding

解决方案

You need to change to triple single quotes ''' or escape the dollar $

Then you'll skip the groovy templating which is what's giving you this issue

这篇关于如何在 Jenkins Groovy 中的多行 shell 脚本中设置变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆