博客
关于我
过滤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/

    你可能感兴趣的文章
    NN&DL4.1 Deep L-layer neural network简介
    查看>>
    NN&DL4.3 Getting your matrix dimensions right
    查看>>
    NN&DL4.8 What does this have to do with the brain?
    查看>>
    No 'Access-Control-Allow-Origin' header is present on the requested resource.
    查看>>
    No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
    查看>>
    No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
    查看>>
    No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
    查看>>
    No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
    查看>>
    No module named cv2
    查看>>
    No module named tensorboard.main在安装tensorboardX的时候遇到的问题
    查看>>
    No module named ‘MySQLdb‘错误解决No module named ‘MySQLdb‘错误解决
    查看>>
    No new migrations found. Your system is up-to-date.
    查看>>
    No qualifying bean of type XXX found for dependency XXX.
    查看>>
    No resource identifier found for attribute 'srcCompat' in package的解决办法
    查看>>
    No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android
    查看>>
    NO.23 ZenTaoPHP目录结构
    查看>>
    NO32 网络层次及OSI7层模型--TCP三次握手四次断开--子网划分
    查看>>
    NoClassDefFoundError: org/springframework/boot/context/properties/ConfigurationBeanFactoryMetadata
    查看>>
    Node JS: < 一> 初识Node JS
    查看>>
    Node-RED中使用JSON数据建立web网站
    查看>>