This script is meant to be used in GitLab CI to automatically open Merge Requests for feature branches, if there is none yet.
The script is provided as dedicated docker image to improve maintainability in the future.
It is based on the script and idea of blog post by Riccardo Padovani. Thanks for providing this.
Set a secret variable in your GitLab project with your private token.
Name it GITLAB_PRIVATE_TOKEN
.
This is necessary to raise the Merge Request on your behalf.
To create the personal token you can go to /profile/personal_access_tokens on your GitLab instance, and then you add to your pipeline following this guide.
Add the following to your .gitlab-ci.yml
file:
stages:
- openMr
Open Merge Request:
image: msonowal/gitlab-auto-mr
before_script: [] # We do not need any setup work, let's remove the global one (if any)
variables:
GIT_STRATEGY: none # We do not need a clone of the GIT repository to create a Merge Request
stage: openMr
only:
- /^feature\/*/ # Means on which branch the automerge will be executed, here we are saying the branches starts with name feature, We have a very strict naming convention
script:
- merge-request.sh # The name of the script
set the MERGE_MAP variable which is json file that has key value mapping of source and target branches mapping to open merge requests
The images are hosted on Docker Hub.
Two tags are noteworthy:
latest
: Latest release onmaster
branch of this project
- Script and idea: Gitlab Blog post