问题求助: Gitlab 如何触发分支自动合并

65 天前
 GKD

有三个分支。 dev, main, prod.

需求:每当我在 gitlab 将 dev 合并到 main 分支。自动触发 main 分支合并到 prod 分支。

写了几个 CI/CD 都有不对,特来问问大佬们

832 次点击
所在节点    GitLab
5 条回复
Jack927
65 天前
这样可行?

```
only:
- main
before_script:
- >
if ! git log -1 --pretty=%B | grep -qE "Merge branch 'dev' into 'main'"; then
echo "无须处理...";
exit 0;
fi
script:
# 这里做你的合并
- 'git merge main prod'
```
GKD
65 天前
@Jack927 直接在 CI/CD 里执行 git 命令会有权限问题。 我现在准备用 GITLAB API 来实现。应该可行。
贴个错误
```
Fetching changes with git depth set to 20...
Initialized empty Git repository in /root/builds/dRuCU3mz/0/York.Yang/git/.git/
Created fresh repository.
Checking out d8e5add6 as detached HEAD (ref is main)...
Skipping Git submodules setup
Executing "step_script" stage of the job script
$ git merge origin/main origin/prod
merge: origin/prod - not something we can merge
ERROR: Job failed: Process exited with status 1
```
chf007
65 天前
只能 api 实现吧
sampeng
65 天前
友情提示。千万别干这种自动的事。偷懒一时爽,代码消失哭的时候在后面
guanzhangzhang
65 天前
你 git merge 之前 git fetch origin/main 试试

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/1021353

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX