Substitutions in environment variable

45 views
Skip to first unread message

Maxim Shaev

unread,
Sep 29, 2019, 8:10:27 AM9/29/19
to go-cd
Hi guys, Is it possible to define a custom environment variable based on standard?
e.g.
```
        <environmentvariables>
          <variable name="APP_VERSION">
            <value>${GO_PIPELINE_LABEL}</value>
          </variable>
```
That doesn't work as expected. The results:
```
GO_PIPELINE_LABEL=dev-107
APP_VERSION=${GO_PIPELINE_LABEL}
```
If no, what's the best way to define that variable?

Manuel Ortiz

unread,
Sep 29, 2019, 10:02:02 PM9/29/19
to go-cd
Hey, are you running on windows or linux agent?

Maxim Shaev

unread,
Sep 30, 2019, 2:44:46 AM9/30/19
to go...@googlegroups.com
> Hey, are you running on windows or linux agent?

Hey, It's Linux (Ubuntu 18.04 server) agent

--
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/464f6d6b-8f40-4c34-9e8c-dffc7129cc75%40googlegroups.com.


--
Best regards,
Maxim Shaev
Message has been deleted

Jason Smyth

unread,
Sep 30, 2019, 11:26:43 AM9/30/19
to go-cd
Hi Maxim,

Maybe I am missing something but why do you want to do this?

Could you not reference the existing variable instead of creating a custom variable that contains the same data?

Regards,
Jason


On Monday, 30 September 2019 02:44:46 UTC-4, Maxim Shaev wrote:
> Hey, are you running on windows or linux agent?

Hey, It's Linux (Ubuntu 18.04 server) agent

On Mon, Sep 30, 2019 at 5:02 AM Manuel Ortiz <jmanue...@gmail.com> wrote:
Hey, are you running on windows or linux agent?



El domingo, 29 de septiembre de 2019, 6:10:27 (UTC-6), Maxim Shaev escribió:
Hi guys, Is it possible to define a custom environment variable based on standard?
e.g.
```
        <environmentvariables>
          <variable name="APP_VERSION">
            <value>${GO_PIPELINE_LABEL}</value>
          </variable>
```
That doesn't work as expected. The results:
```
GO_PIPELINE_LABEL=dev-107
APP_VERSION=${GO_PIPELINE_LABEL}
```
If no, what's the best way to define that variable?

--
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...@googlegroups.com.

Maxim Shaev

unread,
Sep 30, 2019, 1:38:21 PM9/30/19
to go-cd
Hi, Jason
 
Could you not reference the existing variable instead of creating a custom variable that contains the same data?

Unfortunately no, these variables are expected to get as environment variables for k8s manifest template to prepare the manifest file.

Currently the issue is solved by Linux way to set env. variables before command

e.g.
gocd_image_path=${IMAGE_PREFIX}/${GO_PIPELINE_NAME}:${GO_PIPELINE_LABEL} dump-env --template=.env.dist --prefix='gocd_' > .env


Aravind SV

unread,
Oct 1, 2019, 7:44:58 AM10/1/19
to go...@googlegroups.com
Hello Maxim,
Yes, GoCD doesn't substitute environment variables like $GO_PIPELINE_NAME etc. when defining other environment variables.

However, as documented at https://docs.gocd.org/current/faq/dev_use_current_revision_in_build.html, it is possible to get bash to do that for you. It also gives you much more flexibility, since it allows you to do things like: ${ENV_VAR:-default}.

In your case, as long as the command is "sh" or "bash" and the first argument is "-c", you should be able to use exactly what you showed there.

Cheers,
Aravind

Maxim Shaev

unread,
Oct 1, 2019, 7:52:09 AM10/1/19
to go-cd
Thanks Aravind,
I think it's enough to consider the issue is closed. I've solved it in the similar way.
Reply all
Reply to author
Forward
0 new messages