英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论