简体   繁体   English

如何在Thoughtworks Go任务命令中解决环境变量

[英]How to resolve Environmental Variables in a Thoughtworks Go task command

Thoughtworks Go provides a stack of job specific Environmental Variables passed to each task. Thoughtworks Go提供了一系列传递给每项任务的特定于工作的环境变量。 For example my job outputs the same values that the API doc specifies. 例如,我的作业输出与API doc指定的值相同的值。

[go] setting environment variable 'GO_ENVIRONMENT_NAME' to value 'rmp'
[go] setting environment variable 'a' to value 'b'
[go] setting environment variable 'GO_SERVER_URL' to value 'https://10.8.249.57:8154/go/'

I have not been able to resolve vars in a bash task command. 我无法在bash任务命令中解析变量。

[go] Start to execute task: <exec command="echo" >
<arg>${GO_SERVER_URL}</arg>

Just outputs 只是输出

${GO_SERVER_URL}

I have tried... 我试过了...

${GO_SERVER_URL}
${env.GO_SERVER_URL}
${go.GO_SERVER_URL}
$[GO_SERVER_URL]
$GO_SERVER_URL
"${GO_SERVER_URL}"

nothing works... 什么都行不通

Thoughtworks Go has a support page about this exact problem , stating: Thoughtworks Go有一个关于这个确切问题的支持页面 ,说明:

Note that this is a plain exec, not a shell exec, so [$FOO] won't have the desired effect 请注意,这是一个普通的exec,而不是shell exec,因此[$ FOO]将没有所需的效果

The easiest solution: 最简单的解决方案:

command: /bin/bash

args:
-c
echo
$GO_SERVER_URL

The alternative is to simply toss your script into a file. 另一种方法是简单地将脚本放入文件中。

Why do I know this? 为什么我知道这个? Because I ran into it too. 因为我也碰到了它。

For a command with multiple options Go is rather finicky. 对于具有多个选项的命令,Go非常挑剔。 tedder42's answer was correct for the simple echo case but didn't work for me on my real problem using curl with multiple parameters. tedder42的回答对于简单的回声情况是正确的,但对于我使用带有多个参数的curl的真实问题不起作用。 Srinivas Upadhya on the Go Google group helped me out. Sliivas Upadhya on the Go Google小组帮助了我。 I want to document it here for others so it is easy to find. 我想在这里为其他人记录,所以很容易找到。 It looks obvious, but small deviations didn't work. 看起来很明显,但小偏差不起作用。

Enter your command exactly like this: 输入您的命令完全如下: 在此输入图像描述

The XML should look like this: XML应该如下所示:

<tasks>
  <exec command="/bin/bash">
    <arg>-c</arg>
    <arg>curl -o test.file $GO_VAR</arg>
    <runif status="passed" />
  </exec>
  ....
</tasks>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM