I work on a project that is hosted upstream (and I have also stored on my local gitlab installation).
Now I want to define a CI/CD configuration only for my local gitlab, but that file should never be uploaded upstream or should be part if branches that I will later merge into main branch.
I will commit to several branches on my local gitlab and every push to a branch that is not main should trigger the CI/CD pipeline.
The idea is now to have the .gitlab-ci.yml in an extra branch (like ci-cd-config) that is never pushed upstream.
If I need to test commits, I would like to create new branches like fix/feature-1.
The push should trigger now the CI/CD pipeline, like it is defined in file .gitlab-ci.yml which only exists in branch ci-cd-config.
But I cannot define in the CI/CD settings inside the project from where the .gitlab-ci.yml should be used.
I only see the setting: Settings → CI/CD → General pipelines → CI/CD configuration file
But it seems that I cannot tell gitlab to use the file from a very specific branch.
If I understand it correctly, you push your local Git changes into two remotes - upstream, and local network GitLab servers.
To avoid maintaining different branches and .gitlab-ci.yml files, I’d suggest looking into workflow:rules to control when pipelines and jobs should be running. GitLab CI/CD `workflow` keyword | GitLab
Add a rule that checks for a CI/CD variable value, and if matched, it runs the pipeline.
workflow:
rules:
- if: $MY_ENV == "local"
On your local network GitLab server, navigate into the project settings and define the CI/CD variable. Upstream server stays blank. GitLab CI/CD variables | GitLab
Let my phrase my question different and bring also a solution that is working for me.
In the repository there is a branch called main which is synced to upstream repository.
I have in my local repository (and on my hosted gitlab) several other branches.
The .gitlab-ci.yml most not exist in the main branch and therefor must also not exist in any other branch where changes are commited (because a merge of these branches to main would bring the .gitlab-ci.yml then to the main branch which is not wanted).
My first idea was to have a dedicated branch that holds the .gitlab-ci.yml, but I could not found a way to tell gitlab to use the .gitlab-ci.yml from that specific branch to build all commits on all branches.
I tested now successfully another approach.
I created now a completely new repository that only have the .gitlab-ci.yml file and configured gitlab to use this repository/file (there is a configuration option available to point to a remote repository for the pipeline definition).
It is working fine so far.
Only problem is now, that the pipeline is also executed for commits in branch main, which I do not want.
There I need to read a little bit more in the documentation to tell gitlab to run the pipeline not for changes on branch main.
Great idea. This also helps with compliance needs, i.e. that no-one in the project can edit the CI/CD pipeline, and all jobs are always being run.
Only problem is now, that the pipeline is also executed for commits in branch main, which I do not want.
There I need to read a little bit more in the documentation to tell gitlab to run the pipeline not for changes on branch main.
A similar approach to my suggestion above is possible with rules (on the job level) and workflow:rules (global). You’ll need to use a pre-defined CI/CD variable that provides the current Git branch name, and compare it to the main branch.
Thanks, I think the syntax of rules is that is expects an array.
There I found another problem in gitlab.
As the file (.gitlab-ci.yml) is now hosted on a different repository I expected if I click the Go to the pipeline editor: