Using gitlab cicd to automatically merge branches

Viewed 6287

gitlab has this functionality that you can use pipelines that will execute code whenever you push code to your project. this is done through their .gitlab-ci.yml file format

i am trying to somehow make the pipeline to merge all branches with prefix "ready/" i have written a python program to do it locally, but it wont execute on the gitlab docker remote machine. this is due to the fact that it only lists "* and master" as branches with "git branch -a".

i have tried to checkout to master but that dosent work.

is this even possible on the gitlab pipeline? how would i go forward?

1 Answers

There are a couple of ways to achieve this depending what credentials you want to use, what you prefer, and what is better suited to your use case.

  1. Use SSH in CI/CD (with SSH keys) to use your standard git commands to pull, do whatever, then push to the repo as part of a pipeline job.
  2. Use the merge requests API which requires a personal access token. The API allows you to create, accept, and merge a merge request.

If you have a lot of branches, then you may want to use the first method.

Related