Global Env variables using Pipelines as Code?

24 views
Skip to first unread message

Sifu Tian

unread,
Apr 21, 2022, 3:38:18 PM4/21/22
to go-cd
Hi,

I recently converted all of our pipelines to leverage config repository.
One thing I haven't determined is how to get env variables that I can use by all pipelines.
I lose the ability to add the pipelines to any environment that can consume the same env variables.
One approach was to place the variables in my Dockerfile however we have some secure variables that we use that we cant leverage in a dockerfile and placed in SCM (Github)

Can someone tell me how this has been addressed/solved.

Ashwanth Kumar

unread,
Apr 22, 2022, 2:15:19 AM4/22/22
to go...@googlegroups.com
In this example on the README: I see environments and pipelines defined. Does that not help?

--
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/edce1657-6112-4293-8b32-9c24a20dc267n%40googlegroups.com.


--

Ashwanth Kumar / ashwanthkumar.in

Sifu Tian

unread,
Apr 23, 2022, 10:04:43 PM4/23/22
to go-cd
Hi Ashwanth,

Thats for your response.  If I understand the examples in the README, you would have to add "environments" and the "variables" to every yaml file that is hosted in github.
There is no central "Environment group that can be used by the config repository that you can add all the pipelines to.  
I have many pipelines that share the same secure variables that I was able to add them to that environments group when I built out the pipelines manually.
Once I converted them to config repository, it appears I would have to define each pipeline individually with those settings.
Screen Shot 2022-04-23 at 9.05.55 PM.png

Chad Wilson

unread,
Apr 24, 2022, 2:12:25 AM4/24/22
to go...@googlegroups.com
Have you tried having a file in the config repository which declares only top-level environments (with env vars), and then separate files inside the same confi repo which refer to those environments by name inside pipelines?

if I recall correctly, the `n` YAML files discovered by the config repo pattern you configure are merged together and validated as a whole so you should be able to factor them out, I believe?

-Chad

Ketan Padegaonkar

unread,
Apr 24, 2022, 2:20:37 AM4/24/22
to go...@googlegroups.com
The groovy pipeline plugin also allows you to import code so you can just merge some global variables as you need. If you are worried about having to write new config files in groovy - you can simply export and convert json/yaml to groovy.

Alexey Savchkov

unread,
May 8, 2023, 10:45:36 PM5/8/23
to go-cd
Could you please provide a minimum example of importing a function of a Groovy configuration script from a file located in the same directory as the importing Groovy script? Or maybe even put an example into https://github.com/gocd-contrib/gocd-groovy-dsl-config-plugin/tree/master/example/src/main/groovy for future reference.

Thanks a lot.
воскресенье, 24 апреля 2022 г. в 13:20:37 UTC+7, ketanpad...@gmail.com:
Reply all
Reply to author
Forward
0 new messages