Standard environment variables in pipeline job custom command

14 views
Skip to first unread message

Michael Foster

unread,
Oct 17, 2024, 8:50:55 PM10/17/24
to go-cd
I'm using GoCD in Windows environments, and trying to use the standard environment variable GO_PIPELINE_COUNTER to enumerate things distinctly. But I can't get any standard environment variable to work, such as with this kind of command:
```
        <jobs>
          <job name="PullAndUpdate">
            <tasks>
              <exec command="echo">
                <arg>${env.GO_PIPELINE_COUNTER}</arg>
                <runif status="passed" />
              </exec>
```
I've tried with and without braces and parentheses, and with $ and % (# is apparently only for parameters), and with and without "env.". Anything I try just gives me the literal text as output.

Is there any way to actually USE the standard environment variables within a pipeline?


Thank you!!!   Michael F.

Chad Wilson

unread,
Oct 17, 2024, 10:47:01 PM10/17/24
to go...@googlegroups.com
Specifically for windows tasks, "<arg>%GO_PIPELINE_COUNTER%</arg>" should work, since Windows commands are executed via exec

https://docs.gocd.org/current/faq/dev_use_current_revision_in_build.html#2-using-an-environment-variable-in-a-custom-command-on-windows

If that's not working, I'll take a look - might need to update the documentation at the very least. If it's not working, I have a suspicion I know what "broke" it - there were MANY issues earlier with spaces and quoting and arg splitting on Windows and a side effect of fixes for those might have been to affect this. :-)

There will be workarounds involving using cmd /c /s or powershell directly so ensure you get a variable for the "shell" to interpolate, but maybe we start with trying to see whether it works "as documented".

-Chad

--
You received this message because you are subscribed to the Google Groups "go-cd" group.
To unsubscribe from this group and stop receiving emails from it, send an email to go-cd+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/go-cd/2271247d-94f9-4800-b10d-3c00e0c3029en%40googlegroups.com.

Michael Foster

unread,
Oct 18, 2024, 9:02:18 AM10/18/24
to go-cd
Thank you!

My notes say I tried that already, but I tried it again and it works! I've spent hours trying to find out the correct syntax.
Reply all
Reply to author
Forward
0 new messages