GoCD pull from multiple branches and deploy to different environments

Viewed 1831

I'm right now using GoCD for automate our deployments.

These are the versions I'm using.

go-agent  17.10.0-5380
go-server 17.10.0-5380

I'd like to expose a case that I wasn't able to fix just by configuring GoCD, I couldn't find anything that can help me out on that, most likely I'm missing something ;-)

Here's the case I'd like to achive:

We have a GIT repository: frontend-app

In that repo every developer can push changes to different branches following this naming convention: dev-1, dev-2, ...

The goal to achive is that every time a developer pushes changes to dev-1, goCD will take those changes in that branch, build it and deploy to our environment dev-1.

If developer 2 pushes changes to dev-2, goCD will take those changes, build them and deploy to dev-2 environment.

The first I've tried, to achive this, is configure the pipeline using only 1 material and try to use some glob pattern on branch names. As you can see in the attached screenshot.

configure material branch glob pattern

However I couldn't get this working.

The second thing I tried is to use multiple materials. To be able to have multiple materials you need to configure the material giving to it a specific Destination directory. As you can see in the attached screenshot:

configure multiple materials with destination directory

With this approach I was able to have goCD pulling for new changes and checking repo out on the specific Destination directory.

For my pipeline I have configured a template with a bunch of tasks to build the project, before deploying it, ie: npm install, npm test, npm run-script build, etc...

However, those tasks are then executed on the parent directory (go-agent/pipelines/frontend-app/), instead of in the Destination directory (dev-1, dev-2, ...)

go-agent/pipelines/frontend-app/
  |_ dev-1
  |_ dev-2
  |_ ...

I've been reading about goCD environment variables and I couldn't find any variable that holds the destination directory, so I could reference it in my tasks.

Of course, as a solution, you can always create several pipelines in order to achieve this, ie:

frontend-app-dev-1, frontend-app-dev-2, etc...

But my problem is that I have 8 dev environments and also 10 projects. So as you can imagine is quite a job to configure all those things separately.

Specially if later we make any change, that's a lot of work to do it manually and prone to errors.

So my questions are:

  1. in case the first approach (branch glob pattern), can this goal be achieved by using Branch glob pattern ?

  2. if we use second approach (several materials), Does someone know if this can be achieved ? I think I'm almost there, but probably I'm missing something when configuring my tasks.

  3. Any other ideas to be able to get this working ?

  4. Is there any other way to achieve the things I need ?

Thanks in advance.

1 Answers

You really need a pipeline per branch. Each commit triggers a new instance of a pipeline, and if you handle several branches in one pipeline, the history view doesn't distinguish the branches, and you get a jumble of disconnected commits there.

To reduce the configuration overhead, you could use GoCD's pipelines as code feature to write the pipelines as data structures to a git repo, and you can use templating to generate that repo.

The GoCD team considers using such templates to implement wildcard branch support, but it's not yet done.

Related