如何防止dev中的分支合并|舞台master,如果分支名称不是以相应的前缀开头? 分支的名称应以添加代码的名称开头。 例如,要接受master中的合并请求,该分支应称为master / new_merge_config。
请帮助,如何创建类似的规则?还是没有合并规则就可以做到?
答案 0 :(得分:0)
我的Bash脚本不是最好的,但是您可以创建如下代码:
merging:
stage: validation
only: [merge_requests]
script:
- [[ "$CI_MERGE_REQUEST_TARGET_BRANCH_NAME" =~ ^master$ ]] && [[ ! "$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME" =~ ^master ]] && echo 'not allowed merge to master' && exit 1 || echo 'merge master ok'
- [[ "$CI_MERGE_REQUEST_TARGET_BRANCH_NAME" =~ ^stage$ ]] && [[ ! "$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME" =~ ^stage ]] && echo 'not allowed merge to stage' && exit 1 || echo 'merge stage ok'
- [[ "$CI_MERGE_REQUEST_TARGET_BRANCH_NAME" =~ ^dev$ ]] && [[ ! "$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME" =~ ^dev ]] && echo 'not allowed merge to dev' && exit 1 || echo 'merge dev ok'
请参见this list,并在gitlab-ci上提供可用变量