Reputation: 11837
We use a peer-review process where reviewers are asked to merge in to a Review branch when done.
Thing is, after review, we wish that our master branch gets automatically rebased with what Review branch has. This would reflect our current manual process where repo maintainer manually rebases review branch in to master to make a deploy.
How can we achieve this automatization?
Upvotes: 1
Views: 5666
Reputation: 3001
This can be achieved through a gitlab-ci pipeline task. Essentially you will need to merge to master and push. Unfortunately there is no direct way for a gitlab runner to push to remote.
The below is a workaround
before_script
Sample code below
merge_to_master:
before_script:
- which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )
- eval `ssh-agent -s`
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- ssh-keyscan -H <Your gitlab server> >> ~/.ssh/known_hosts
- ssh -vT git@<Your gitlab server>
variables:
VERSION: "$CI_PIPELINE_ID"
VERSIONNAME: "$CI_COMMIT_REF_SLUG"
only:
- <Review* or similar>
script:
- export LC_CTYPE=en_US.UTF-8
- git config --global user.email "Some user email - Typically the machine user"
- git config --global user.name "Some name"
- git checkout master
- git merge $CI_COMMIT_REF_NAME
- git push ssh://git@<Your gitlab server>/<Repo> HEAD:master
stage: dev_deploy
$SSH_PRIVATE_KEY
- Environment variable containing the private SSH key for git Refer https://help.github.com/en/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent
[ci skip]
- Add only if you want to skip the build after the push
Upvotes: 1