How to resolve Environmental Variables in a Thoughtworks Go task command

2k views Asked by At

Thoughtworks Go provides a stack of job specific Environmental Variables passed to each task. For example my job outputs the same values that the API doc specifies.

[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.

[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...

2

There are 2 answers

0
jeremyjjbrown On

For a command with multiple options Go is rather finicky. 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. Srinivas Upadhya on the Go Google group helped me out. 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: enter image description here

The XML should look like this:

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

Thoughtworks Go has a support page about this exact problem, stating:

Note that this is a plain exec, not a shell exec, so [$FOO] won’t have the desired effect

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.