我正试图在groovy步骤中再次使用sh“”“”“”中的shell脚本中设置的VAR_NAME值,但出现以下错误。我只看到了有关如何在shell中使用groovy变量的问题,但没有其他问题。预先感谢。
groovy.lang.MissingPropertyException:没有此类属性:groovy.lang.Binding
的VAR_NAMESizedBox(
height: ... // an arbitrary height, needed because I have multiple of these in a column
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemBuilder: (context, i) => Column(
children: [
Expanded(images[i]), // an image
Text(captions[i]), // a caption
]
),
),
)
答案 0 :(得分:4)
发出sh
指令时,将创建一个新的Shell实例(很可能是bash
)。与通常的Unix进程一样,它继承父级的环境变量。然后,您的bash
实例正在运行您的脚本。当脚本设置环境变量时,bash
的环境将更新。脚本结束后,运行脚本的bash
进程将被销毁,并且其所有环境也将随之销毁。
如果要使用该shell实例设置的任何内容,则需要将其放入,例如:
def script_output = sh(returnStdout: true, script: """
#!/bin/bash
set -e
set +x
VAR_NAME=10
echo \$VAR_NAME
""")
script_output = script_output.trim()
VAR_NAME = script_output
echo "VAR_NAME is ${VAR_NAME}"