Global Variable - GO CD

170 views
Skip to first unread message

nitesh...@gmail.com

unread,
Jan 8, 2021, 7:43:23 AM1/8/21
to go-cd
Hi,

is there any way we can use a lobal variable and use that variable in my GO pipe Material path - like TFS repo path

This is really urgent , and quick help will be very much appreciated. Thanks in advance  

Regards, Nitesh 

Ashwanth Kumar

unread,
Jan 8, 2021, 8:02:24 AM1/8/21
to go...@googlegroups.com
You could use Parameters for that purpose. 

--
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/aee436d7-9c27-4005-9d35-070aed4e048an%40googlegroups.com.

nitesh...@gmail.com

unread,
Jan 8, 2021, 8:15:34 AM1/8/21
to go-cd
Thanks ,

but i can't see any option to set parameter global to the environment , do we have any other option ?

i have got 100 pipes, where having same TFS path but dynamic change number, which needs to concatenated with TFS path   , so we want to execute 100 pipes in one for different -different change number on adhoc basis.

Ashwanth Kumar

unread,
Jan 8, 2021, 8:35:47 AM1/8/21
to go...@googlegroups.com
IMHO, Environment in GoCD helps in grouping pipelines to provide environment related settings (via environment variables) or agents (that have environment specific access / configurations). A variable used in the pipeline's material isn't specific to an environment and also Parameters are specific to a pipeline. So much so, that when a pipeline is saved all the parameters that are referred within (either on config / jobs / stages) should be available else the config validation would fail and the new pipeline changes wouldn't get saved. 

For your current situation, I do have a few suggestions:
1. If you're creating the pipelines right now, I would recommend using the YAML / JSON DSL which would make your life easier. You can find and replace the values quickly. 
2. If these 100s of pipelines already exist, During an off-peak time / with maintenance mode enabled -- You can import the config.xml locally and find-replace the material path and import the new config back as a one time migration. 

Thanks,




--

Ashwanth Kumar / ashwanthkumar.in

nitesh...@gmail.com

unread,
Jan 8, 2021, 9:37:26 AM1/8/21
to go-cd
Thanks,
Yes, these pipeline already exists.

but updating the config XML every time when we will have new change from client will be risky.

request you to please help another way around ?

Marques Lee

unread,
Jan 8, 2021, 10:57:11 AM1/8/21
to go-cd
I would just do what Ashwanth suggested with Environments: put your pipelines (and agents!) in the same environment and then you can apply these (e.g., environment variables) globally to all pipelines in that environment.

Marques Lee

unread,
Jan 8, 2021, 11:05:51 AM1/8/21
to go-cd
Actually, nevermind on the environment variable - I don't think you can use those in materials, and you're wanting to use it there it seems. Using pipelines as code would really be the best option, IMO.

Marques Lee

unread,
Jan 8, 2021, 11:08:50 AM1/8/21
to go-cd
But, since that's a lot of work and you need a solution in the immediate, I think your only option is to bulk-edit the config XML and do this with a good text editor.

Nitesh Kumar

unread,
Jan 8, 2021, 2:39:59 PM1/8/21
to go...@googlegroups.com
Hi,

Thanks,  I can editing config.xml but doing everytime for each change number would be really horrible 😞 

Any other ideas?

It looks a wiered case that we can't use env variables in materials even my pipeline does exist in the same environment 

Marques Lee

unread,
Jan 8, 2021, 4:54:48 PM1/8/21
to go...@googlegroups.com
When the server needs to check a material in the flyweight directory to determine whether it should schedule pipelines, it doesn’t bind environment variables, most likely because environment variables are scoped to a single pipeline. On the other hand, materials aren’t necessarily unique to a pipeline. The same material can be used in other pipelines and contexts (eg, config repo) so the material service wouldn’t have defined behavior for other uses to bind environment variables, which are scoped to a single pipeline. At least that’s what I am inferring off the top of my head without digging into the code too much.

So, unfortunately, there’s no solution that is both quick and long-term that I’m an think of. The quick one is bulk editing your config xml. The long term is reimplementing in pipelines as code so that you can apply changes to multiple pipeline config a very easily.

Nitesh Kumar

unread,
Jan 10, 2021, 2:08:49 AM1/10/21
to go...@googlegroups.com
Thanks,

So, do we have any endpoint which updates the pipeline ?

Regards, Nitesh 



--
Thanks&Regards

Nitesh kumar

Ashwanth Kumar

unread,
Jan 10, 2021, 2:22:17 AM1/10/21
to go...@googlegroups.com
You can check the GoCD APIs online at https://api.gocd.org/ (against the corresponding version of your GoCD Server).

If you're planning to automate your way through, https://github.com/gocd-contrib/gomatic might be of your interest. 


Nitesh Kumar

unread,
Jan 10, 2021, 3:12:11 AM1/10/21
to go...@googlegroups.com
Thanks,

Yes, i am planning to automate and to update materials before executing my pipes.

i have gone through the APIs but i can't find any endpoint which updates the pipeline, do we have any?



--
Thanks&Regards

Nitesh kumar

Nitesh Kumar

unread,
Jan 11, 2021, 6:04:38 AM1/11/21
to go...@googlegroups.com
HI  Ashwanth,

Do we have any API open which updates the Project path of the material ? I have searched in the GOCD API section but i can't find it.

Request you to please help on this.

Regards, Nitesh 
--
Thanks&Regards

Nitesh kumar

Aravind SV

unread,
Jan 11, 2021, 6:21:22 AM1/11/21
to Nitesh Kumar, go...@googlegroups.com

Materials are part of a pipeline and so, they are updated using the “Edit pipeline config” API call: https://api.gocd.org/current/#edit-pipeline-config

You’ll need to do a GET and then a PUT with an If-Match header based on the GET response: https://developer.mozilla.org/en-US/docs/Web/HTTP/Conditional_requests

Nitesh Kumar

unread,
Jan 15, 2021, 2:22:28 PM1/15/21
to Aravind SV, go...@googlegroups.com
Hi Aravind,

i have tried editing pipeline config using PUT method and i am sending the Json on the basis of output i had using GETmethod for one pipeline but it is throwing an error while validating Json. below is the command i am using

$putResponse = D:\temp\curl.exe  -X PUT -u 'test:****' -H 'Accept: application/vnd.go.cd.v4+json' -H 'Content-Type: application/json' -H 'If-Match: "********"' 'http://********:8153/go/api/admin/pipelines/testpipe' -d $text

Request you to please help on this.

Regards, Nitesh 

On Mon, Jan 11, 2021 at 4:51 PM Aravind SV <aven...@thoughtworks.com> wrote:

Materials are part of a pipeline and so, they are updated using the “Edit pipeline config” API call: https://api.gocd.org/current/#edit-pipeline-config

You’ll need to do a GET and then a PUT with an If-Match header based on the GET response: https://developer.mozilla.org/en-US/docs/Web/HTTP/Conditional_requests



--
Thanks&Regards

Nitesh kumar

Aravind SV

unread,
Jan 16, 2021, 7:20:56 AM1/16/21
to Nitesh Kumar, go...@googlegroups.com

I’d suggest doing a GET and then makee no change and do a PUT. That should work. If it doesn’t, you probably have some of the parameters wrong in your request.

Reply all
Reply to author
Forward
0 new messages