如何在步骤之间传递.gitlab-ci.yml的依赖关系

huangapple go评论79阅读模式
英文:

How to pass .gitlab-ci.yml dependencies between steps

问题

以下是您提供的内容的中文翻译:


stages:
  - Linter

install:
  stage: Linter
  tags: ['checker']
  script:
    - pip install -r path/to/requirements.txt

black:
  stage: Linter
  tags: ['checker']
  needs: ['install']
  script:
    - python3 -m black --line-length 140 --check .

isort:
  stage: Linter
  tags: ['checker']
  needs: ['install']
  script:
    - python3 -m isort --check-only .

flake8:
  stage: Linter
  tags: ['checker']
  needs: ['install']
  script:
    - python3 -m flake8 .

由于项目是一个Django应用程序,我需要在执行black、isort和flake8检查之前安装一些自定义依赖项。上述问题似乎是在“install”完成后,其他作业无法检测到已安装的依赖项。因此,所有三个作业都会出现“没有找到模块black”(或“flake8”或“isort”的)错误。

我假设“needs”是我需要添加的内容,但它并没有改变任何情况。

英文:

My .gitlab-ci.yml looks like this:


stages:
  - Linter

install:
  stage: Linter
  tags: ['checker']
  script:
    - pip install -r path/to/requirements.txt

black:
  stage: Linter
  tags: ['checker']
  needs: ['install']
  script:
    - python3 -m black --line-length 140 --check .

isort:
  stage: Linter
  tags: ['checker']
  needs: ['install']
  script:
    - python3 -m isort --check-only .

flake8:
  stage: Linter
  tags: ['checker']
  needs: ['install']
  script:
    - python3 -m flake8 .

Since the project is a Django app, I need some custom dependencies installed before performing black, isort and flake8 checks. The problem above is that apparently after install is done, the other jobs cannot detect installed dependencies. So all three get errors No module named black (or flake8, or isort).

I assumed that needs is what I need to add, but it does not change anything.

答案1

得分: 1

你需要将工作分成两个阶段。
在第一个阶段,你需要安装这些包,然后可以使用artifacts关键字将这些包传递给第二个阶段(Linter)(请参考https://docs.gitlab.com/ee/ci/yaml/#artifacts)。

你可以使用虚拟环境来安装你的Python包。这可能会使得处理artifacts时的路径更容易一些。

英文:

You have to split your jobs into two stages.
In the first stage you have to install the packages and after that you can pass the packages to the second stage (Linter) by using the artifacts keyword (see https://docs.gitlab.com/ee/ci/yaml/#artifacts).

You can use a virtual env to install your python packages. This might make it easier with the paths for the artifacts.

huangapple
  • 本文由 发表于 2023年7月13日 14:45:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/76676590.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定