Home > database >  How to skip some file during merge request on gitlab
How to skip some file during merge request on gitlab

Time:05-07

I am having two branches on GitLab(1.Staging & 2.Production). In my Angular and NodeJS application there is one part(e.g. Contact us ), which I don't want to deploy on production.

I want it in staging branch but not in production branch.

So my question is how can I skip the specific code during merging of two branches in GitLab.

I am using Merge requests button for merging. but I have .gitignore, .gitattributes & .gitlab-ci.yml files.

Please help me, Thanks in advance

CodePudding user response:

As explained here, there is no obvious way to have a file in one branch, but not (after a merge) in another.

If you can have that same file in both branches, but with a content (in prod) which would not be impactful, then you can put a merge driver in place in order to keep that prod content whenever you merge from staging.
However, this is a local solution, not one you can set when clicking Merge directly on GitLab.

CodePudding user response:

One option is deleting the unnecessary files in a pre-deploy stage only for production.

You can even edit files before deploying. For example, we use sed commands to update our settings file before deploy in production.

pre-deploy:
  <<: *default_config
  stage: pre-deploy
  image: $CI_REGISTRY_IMAGE:latest
  only:
    - production
  script:
    - echo "delete unnecessary  files"
    - # SED https://www.geeksforgeeks.org/sed-command-in-linux-unix-with-examples/
  • Related