Gitlab .gitlab-ci.yml file different in branches

Viewed 10029

I have the situation where we have .gitlab-ci.yml in master which is different in brach 'development' the problem is we have a lot of repos with a lot of branches.

I want to make a change to .gitlab-ci.yml but I want to be sure all branches are using the same .gitlab-ci.yml. I know gitlab by design leave you to have different CI CD for your branches because your pipelines could be different.

One way to do it is to get all repos with all branches and just copy the same .gitlab-ci.yml to all repos and branches.

Do you know some kind of better way to do it ?

4 Answers

You can use the include keyword. It allows you to include a file from a remote URL or a special project containing your pipelines. You can, for example, create lots of "hidden" templates prefixing them with . and then including them into your pipeline using the extends keyword as needed. This also allows you to configure your pipeline template using variables.

Note: The include is executed when the pipeline is created. It is therefore not possible to fix a pipeline after it has been created by fixing the included file.

Old answer:

If you use the enterprise edition you can use the include keyword.

If you are using the community edition, the best option I can think of is having a check-yaml job. It basically runns git diff master -- .gitlab-ci.yml[1]. If the .gitlab.yml on the branch and master differ, the job will fail, forcing you to update your branch. While this will not keep your pipelines in sync automatically, a diversion will not go unnoticed.

[1]: You might need to run git fetch master, depending on your git strategy.

I know that .gitlab-ci.yml can be different in branches because your Prod CI could be different from 'Dev/Test' in your other branches , so its normal to have different .gitlab-ci.yml files in different branches ,so our dev team merge master with their branches and start changesfrom there.

The idea is when you want to make lets say 'Global' change but its a matter how you will approach.

You can configure only file .gitlab-ci.yml on external repository for all braches.

You go to repository --> Settings --> General pipelines --> CI/CD Configuration file.

When you do change on any branches, this file is download from repository and apply. On the jobs, you have to configure the "only: - " to exec this job on this branch.

Related