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

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

问题描述

假设我在Jenkins中有一个包含多行shell脚本的Groovy脚本。我如何设置和使用该脚本中的变量?正常的方式会产生一个错误:

$ $ $ $ p $ $ $ $ $ $ $ $ $ $ $ foo




抓住:groovy.lang。 MissingPropertyException:No such property:foo for class:groovy.lang.Binding



解决方案

更改为三倍单引号'''或转换美元 \ $



然后,您将跳过常规模板,这是什么给你这个问题


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天全站免登陆