You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GitLab合并请求流水线仅运行部分Lint作业求助

问题描述

使用GitLab Community Edition v18.9.1搭建流水线,针对main分支和合并请求(MR)构建Docker镜像并执行Lint任务。流水线通过触发下游流水线运行Lint作业,但MR流水线中仅python-format-check作业执行,另外两个Lint作业未被触发。

相关配置文件如下:

.gitlab-ci.yml

---
include:
  - project: sentinel
    file: ci/pipeline.yml
    ref: main

pipeline.yml

---
include:
  ...
  - local: ci/triggers.yml

default:
  timeout: 10m

variables:
  ..

stages:
  - triggers
  - ...

lint.yml

---
include:
  local: ci/_base.yml

stages:
  - lint

.linter-base:
  stage: lint
  extends: .sentinel-standard-rules
  image: ${SENTINEL_LINTER_IMAGE}
  needs: [ ]

.linter-report:
  extends: .linter-base
  variables:
    RUFF_ARGS: ''
  script:
    - |
      set -x
      ruff check $RUFF_ARGS --output-format=gitlab --output-file=gl-code-quality-report.json .
  artifacts:
    when: always
    reports:
      codequality: gl-code-quality-report.json

python-code-style-check:
  allow_failure: false
  extends: .linter-report

python-code-todo-and-fixme-finder:
  extends: .linter-report
  allow_failure: true
  script:
    - |
      ruff check --isolated --select FIX,TD006,ERA001 --output-format=gitlab  . > report.json || true
      jello '[item.update({"severity": "info"}) or item if item.get("severity") == "major" else item for item in _]' < report.json > gl-code-quality-report.json

python-format-check:
  extends: .linter-base
  allow_failure: true
  script:
    - ruff format --check .

_base.yml

---
.sentinel-standard-rules:
  rules:
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"
    - if: $CI_PIPELINE_SOURCE == "parent_pipeline"
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
    - if: $CI_PIPELINE_SOURCE == "web"
    - if: $CI_PIPELINE_SOURCE == "pipeline"

triggers.yml

.trigger-base:

trigger-lint:
  stage: triggers
  trigger:
    include:
      - local: ci/lint.yml
    strategy: depend
  needs:
    - job: some-build-job
    - job: some-other-job
      optional: true

现象

  • main分支流水线:三个Lint作业均正常运行
    main分支流水线显示三个作业均已运行
  • MR流水线:仅python-format-check作业执行
    合并请求流水线仅执行一个作业
解决方案

1. 检查下游流水线规则评估详情

进入MR的下游lint流水线,点击未触发作业名称旁的"i"图标,查看规则评估结果,确认是哪个规则未匹配导致作业被排除。

2. 开启父流水线变量转发

修改triggers.yml中的trigger-lint配置,确保父流水线的MR相关变量传递到下游:

trigger-lint:
  stage: triggers
  trigger:
    include:
      - local: ci/lint.yml
    strategy: depend
    forward:
      pipeline_variables: true  # 转发父流水线所有变量到下游
  needs:
    - job: some-build-job
    - job: some-other-job
      optional: true

3. 优化规则匹配逻辑

修改_base.yml中的.sentinel-standard-rules,添加MR场景的直接匹配条件:

.sentinel-standard-rules:
  rules:
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"
    - if: $CI_PIPELINE_SOURCE == "parent_pipeline"
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
    - if: $CI_PIPELINE_SOURCE == "web"
    - if: $CI_PIPELINE_SOURCE == "pipeline"
    - if: $CI_MERGE_REQUEST_ID  # 通过MR ID存在判断当前为MR场景

4. 排查Code Quality报告冲突

临时移除其中一个未触发作业的artifacts.reports.codequality配置,测试是否能触发作业,确认是否存在多报告冲突导致GitLab自动跳过作业。

5. 检查Ruff配置

确认项目根目录的ruff.toml或.ruff.toml中没有针对MR场景的特殊排除规则,避免因无文件可检查导致作业被跳过。

内容的提问来源于stack exchange,提问作者k0pernikus

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.11 10:05:08