跳至主要內容
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?

4563博客

全新的繁體中文 WordPress 網站
  • 首頁
  • gitlab ci 如何在提交到 master 分支前进行验证,通过验证才能 merge 或 push
未分類
27 8 月 2020

gitlab ci 如何在提交到 master 分支前进行验证,通过验证才能 merge 或 push

gitlab ci 如何在提交到 master 分支前进行验证,通过验证才能 merge 或 push

資深大佬 : css3 9

请教下各位大佬:

  • 写了个验证脚本,放到代码工程中,并且将执行任务加到 ci stage 里边了
  • 但现有的 ci 执行顺序是大家先 push 或 merge 然后才进入 stage 自动流程,然后才走的脚本验证流程,所以这个验证功能并没有什么用,验证未通过时,也还是合到 master 上了
  • 怎么才能在 merge 或 push 前验证出来结果呢?验证不过,就拒绝提交 master
大佬有話說 (32)

  • 資深大佬 : virusdefender

    ci 中加一项跑你的验证,依赖 staging 那一步,跑完了整个 ci 才结束

  • 主 資深大佬 : css3

    @virusdefender
    加了啊,问题在于,现有顺序是先提交后才触发执行 ci 。应该要先执行 ci,验证结果通过后才能 push 或 merge

  • 資深大佬 : Chingim

    Pipelines for Merge Requests
    https://docs.gitlab.com/ee/ci/merge_request_pipelines/

  • 資深大佬 : maichael

    锁分支,不给直接推送,然后手动在界面上提交合并请求

  • 資深大佬 : AngryPanda

    走 MR,不要给权限直接客户端操作

  • 資深大佬 : virusdefender

    @css3 你们直接 push master ? 应该用 merge request

  • 資深大佬 : NauxLiu

    1. 将 master 设置为 protect branch,不允许直接 Push
    2. 打开项目的 Merge Request 设置里的 Pipelines must succeed

  • 主 資深大佬 : css3

    @virusdefender 有 MR,但大家不遵守规范,一股脑提过来,要人工检查,索性就写了个脚本自动验证,这不是没按预计想的那样运行么

  • 資深大佬 : wxsm

    我刚好也在搞这个。目前在尝试 gitlab 前面再对接一个 gerrit

  • 資深大佬 : wxsm

    但是不太顺利,怎么说呢,gerrit 能 push 的,人也能,人不能 push 的,gerrit 也不能。ce 没有评审功能很蛋疼。

  • 主 資深大佬 : css3

    @NauxLiu
    2 这个,是大家各自的分支上跑各自的 pipelines? 跑失败的时候,提不了 mr 吗?

  • 主 資深大佬 : css3

    @wxsm 有好的方案,分享一下哈

  • 資深大佬 : NauxLiu

    @css3 #11 是提交的 PR 对应的 Pipeline 如果没通过不能被 merge,

  • 資深大佬 : taogen

    The branch you are building and testing on is only for building and testing.
    On your dev branch if any tests fail you just fix it and push it again.

  • 資深大佬 : skyadmin

    master 分支设为保护分支,不允许任何人,直接推送代码至 master 分支。就可以让大家必须都在 merge request 了。

  • 資深大佬 : skyadmin

    项目的 settings – repository – Protected Branches 里设

  • 資深大佬 : skyadmin

    然后勾选 settings – General – Merge request,勾选 Only allow merge requests to be merged if the pipeline succeeds 。
    和#7 说的一样,只是给了下具体操作路径。

  • 資深大佬 : 1109599636

    我的理解是个人提交到个人分支,然后个人分支跑 ci 各种流程,ci 通过了才可以 merge 到公共分支吧。如果在 commit 之前就做检查可以用 pre-commit hooks

  • 資深大佬 : StarUDream

    目前用的就是 15-17 所说的方法,目测可以解决主问题。

  • 資深大佬 : 594duck

    @StarUDream 主回复说不想一个个看就想自动化跑跑测测。

    这种敏捷式开发,后面要吃瘪的。

  • 資深大佬 : nightwitch

    禁止提交到 master,要提交到 master 发 pull request 。发 pull request 的时候自动触发 CI 测试,CI 测试不过不允许合并

  • 資深大佬 : zmxnv123

    git hook?

  • 資深大佬 : Rwing

    @nightwitch 这个是正解

  • 資深大佬 : Sapp

    coommit 可以添加钩子啊,前端就有个叫哈士奇的,不通过 commit 都没办法提交

  • 資深大佬 : phy25

    比较优雅的办法,自动提交 MR:

    https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html

    https://docs.gitlab.com/ee/user/project/push_options.html

    git push -o merge_request.create -o merge_request.target=my-target-branch -o merge_request.merge_when_pipeline_succeeds

  • 資深大佬 : janxin

    禁止 master 分支直接提交

    设置 Protected Branches

    合并 MR 需要在 pipelines 执行成功

    设置 Only allow merge requests to be merged if the pipeline succeeds

  • 資深大佬 : maltoze

    https://github.com/pre-commit/pre-commit

  • 資深大佬 : gen900

    gitlab 里 没有通过 pipeline 的 merge request 不让合并的。就是你 push 后就在做 ci 了如果失败 mr 不让合并

  • 資深大佬 : wshcdr

    同意 MR 的做法

  • 資深大佬 : otakustay

    按照主的要求,其实你一开始就应该用 gerrit 而不是 gitlab

  • 資深大佬 : dddd1919

    提 git 的人不按规范执行,总有方法绕过你的设置,不统一提交规范,其他的就别扯了
    用 git 靠的是约定,不是靠各种限制,如果大家都不遵守约定,那就找人专门来干这事,或者换个工具吧。
    统一 git flow,再用 ci 才能达到比较好的效果,比如配置 ci 在 feature 上执行,禁用 remote push master,合并 mr 前要 ci 通过,ci 同时配置 build 和 run test 等等

  • 資深大佬 : icylogic

    我们 master/develop 任何人都不能推的,所有更改都要通过其他分支提 mr,mr 只能由 reviewer 点合并,如果 ci pipeline 挂掉或者有 conflict,合并按钮都是灰的没法点(可以选项里改)

文章導覽

上一篇文章
下一篇文章

AD

其他操作

  • 登入
  • 訂閱網站內容的資訊提供
  • 訂閱留言的資訊提供
  • WordPress.org 台灣繁體中文

51la

4563博客

全新的繁體中文 WordPress 網站
返回頂端
本站採用 WordPress 建置 | 佈景主題採用 GretaThemes 所設計的 Memory
4563博客
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?
在這裡新增小工具