How to ignore .gitlab-ci.yml file when merging the branches

Hi I am creating different branches.I have a different setup in each Branch.

when i am merging both brnaches my gitlab-ci.yml file also merging and overwriting the changes of the target branch.

I want to exclude .gitlab-ci.yml file while merging 2 branches. is it possible? or is there any way I can make it templates?

I have the same problem. Do really nobody knows a ansswer?

I have the same problem but i see no responses anywhere, is it done or there is a way to do it ?

Hi,

I could think of merge strategies, e.g. ours. Lately I had seen that you can do that within .gitattributes for specific files in a persistent way. Though you need to do a deep dive into merge drivers, with first creating ours always returning true.

git config --global merge.ours.driver true

Then you can add a new file called .gitattributes (or modify an existing one), add and commit that then.

.gitlab-ci.yml merge=ours

This works with local merges, but also needs installment on the GitLab server, e.g. when a Merge Request should be merged.

Cheers,
Michael

1 Like

Have the same gitlab-ci.yml file in all the branches and have different job with “only” tag having the branch name.

job:
only - <branch_name>

Example:

production copy job:
  stage: deploy
  tags:
    - production
  script:
    - aws s3 sync dist/ s3://prod-bucket/
  only:
    - production
staging copy job:
  stage: deploy
  tags:
    - staging
  script:
    - aws s3 sync dist/ s3://staging-bucket/
  only:
    - staging

Just an example solution, haven’t tried this yet.

Gitlab guys just added docs how to setup global config value in gitlab.rb Git attributes | GitLab

  1. Edit /etc/gitlab/gitlab.rb.
  2. Add configuration similar to the following:
gitaly['configuration'] = {
  # ...
  git: {
    # ...
    config: [
      # ...
      { key: "merge.ours.driver", value: "true" },
    ],
  },
}

Original issue solved Use gitattributes custom merge driver in MRs (#18830) · Issues · GitLab.org / GitLab · GitLab

1 Like