博客
关于我
过滤gitlab特殊的push请求(四)jenkins+gitlab
阅读量:377 次
发布时间:2019-03-05

本文共 733 字,大约阅读时间需要 2 分钟。

GitLab 中创建分支通常会触发 Jenkins 流水线运行,但这种触发可能会浪费资源。为了优化流程,我们需要过滤特定的 push 请求,避免不必要的流水线触发。

特征分析

创建新分支的 push 操作可能会触发流水线,但可以通过检查特定特征来过滤。例如:

  • 分支创建操作的 commit 提交数以 40 个零结尾(如 40 个零结尾的 commit ID,如 4040000000000000000000
  • 通过 commit 标记区分新建分支(如 v1.0.0 而非 push 操作)

官方解决方案

GitLab 提供了基于 commit 特征的过滤规则:

  • 如果 commit ID 以 40 个零结尾,则拒绝触发流水线
  • 如果 commit msg 明确指明是新建分支(如 new branch),则拒绝触发流水线

变量新增

在流水线配置中新增三个变量:

  • is_new_branch:判断是否为新建分支(true/false)
  • commit_id:获取最新 commit ID
  • commit_message:获取 commit 消息
  • 正则表达式

    流水线脚本中增加正则匹配:

    push -c "HEAD:$(git branch --show-current)"

    匹配规则:

    • push -c "HEAD: 开头
    • 不是 40 个零开头
    • 不是 40 个零结尾

    测试验证

    在 GitLab 进行新建分支操作后,检查 Jenkins 流水线是否被拒绝触发。确保以下情况:

  • 正常提交(非新建分支)流水线正常运行
  • 新建分支操作流水线被拒绝
  • 处理错误情况(如配置错误导致正常提交无法生效)
  • 通过以上优化,能够有效过滤不必要的 push 请求,节省资源并提升流水线效率。

    转载地址:http://jnwwz.baihongyu.com/

    你可能感兴趣的文章
    npm安装教程
    查看>>
    npm报错Cannot find module ‘webpack‘ Require stack
    查看>>
    npm报错Failed at the node-sass@4.14.1 postinstall script
    查看>>
    npm报错fatal: Could not read from remote repository
    查看>>
    npm报错File to import not found or unreadable: @/assets/styles/global.scss.
    查看>>
    npm报错TypeError: this.getOptions is not a function
    查看>>
    npm报错unable to access ‘https://github.com/sohee-lee7/Squire.git/‘
    查看>>
    npm淘宝镜像过期npm ERR! request to https://registry.npm.taobao.org/vuex failed, reason: certificate has ex
    查看>>
    npm版本过高问题
    查看>>
    npm的“--force“和“--legacy-peer-deps“参数
    查看>>
    npm的安装和更新---npm工作笔记002
    查看>>
    npm的常用操作---npm工作笔记003
    查看>>
    npm的常用配置项---npm工作笔记004
    查看>>
    npm的问题:config global `--global`, `--local` are deprecated. Use `--location=global` instead 的解决办法
    查看>>
    npm编译报错You may need an additional loader to handle the result of these loaders
    查看>>
    npm设置淘宝镜像、升级等
    查看>>
    npm设置源地址,npm官方地址
    查看>>
    npm设置镜像如淘宝:http://npm.taobao.org/
    查看>>
    npm配置安装最新淘宝镜像,旧镜像会errror
    查看>>
    NPM酷库052:sax,按流解析XML
    查看>>