gitlab ci在每个阶段运行一条管道

时间:2020-08-10 11:48:12

标签: gitlab gitlab-ci

我正在研究一个项目,现在我正在向其中添加基本的.gitlab-ci.yml文件。我的问题是为什么gitlab在每个阶段都要运行管道?我在做什么错了?

我的项目结构树:
enter image description here

我的基本.gitlab-ci.yml:

stages:
  - analysis
  - test

include:
  - local: 'telegram_bot/.gitlab-ci.yml'
  - local: 'manager/.gitlab-ci.yml'
  - local: 'dummy/.gitlab-ci.yml'

pylint:
  stage: analysis
  image: python:3.8
  before_script:
    - pip install pylint pylint-exit anybadge
  script:
    - mkdir ./pylint
    - find . -type f -name "*.py" -not -path "*/venv/*" | xargs pylint --rcfile=pylint-rc.ini | tee ./pylint/pylint.log || pylint-exit $?
    - PYLINT_SCORE=$(sed -n 's/^Your code has been rated at \([-0-9.]*\)\/.*/\1/p' ./pylint/pylint.log)
    - anybadge --label=Pylint --file=pylint/pylint.svg --value=$PYLINT_SCORE 2=red 4=orange 8=yellow 10=green
    - echo "Pylint score is $PYLINT_SCORE"
  artifacts:
    paths:
      - ./pylint/
    expire_in: 1 day
  only:
    - merge_requests
    - schedules

telegram_bot / .gitlab-ci.yml:

telbot:
  stage: test
  script:
    - echo "telbot sample job sucsess."

manager / .gitlab-ci.yml:

maneger:
  stage: test
  script:
    - echo "manager sample job sucsess."

dummy / .gitlab-ci.yml:

dummy:
  stage: test
  script:
    - echo "dummy sample job sucsess."

我的管道如下所示:
two pipelines

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:0)

之所以发生这种情况,是因为您的analysis阶段仅在merge_requestsschedules上运行,而您未指定其运行的其他步骤(在这种情况下是作业)将在每个branches

上运行

打开MR时,gitlab将在单独的管道中对MR(注意detached标签)和其他三个进行分析。

要修复此问题,请将其放在所有清单中。

 only:
    - merge_requests

从文档中:https://docs.gitlab.com/ee/ci/yaml/#onlyexcept-basic

If a job does not have an only rule, only: ['branches', 'tags'] is set by default.