Pip 在作业之间共享已安装的要求
我有以下带有3个不同作业的yml配置文件:Pip 在作业之间共享已安装的要求,pip,continuous-integration,gitlab-ci,Pip,Continuous Integration,Gitlab Ci,我有以下带有3个不同作业的yml配置文件: stages: - build - test - analyze build: stage: build script: - apt-get update -qy - apt-get install -y python3-dev python3-pip - pip3 install -r requirements.txt test: stage: test script: - covera
stages:
- build
- test
- analyze
build:
stage: build
script:
- apt-get update -qy
- apt-get install -y python3-dev python3-pip
- pip3 install -r requirements.txt
test:
stage: test
script:
- coverage run --source='.' manage.py test
cache:
paths:
- .coverage
analyze:
stage: analyze
script:
- flake8
- coverage report
在第一项工作中,我安装了需求,其中包括覆盖率或flake8。但这些工具用于以下工作。我尝试过使用“依赖项”或“缓存”,但没有成功:只能共享项目根目录下的文件/dir,而不能共享/user/local/bin下的二进制文件
我试图为pip安装指定另一个目录,但二进制文件安装在/user/local/bin中
我发现的解决方法是在每个作业中安装依赖项,但我认为这是不太理想的解决方案
我认为必须有更好的解决办法
谢谢。我刚刚找到了一个解决方案,至少对于python3(对我来说足够了): python3有一个用于管理虚拟环境的内置工具:venv 使用venv,我们可以在项目根目录中创建虚拟环境,缓存该目录,并在每个作业中启用虚拟环境
variables:
VENV_NAME: "env"
cache:
paths:
- $VENV_NAME
first_job:
script:
- apt-get update -qy
- apt-get install -y python3-dev python3-pip python3-venv
- python3 -m venv $VENV_NAME
- source $VENV_NAME/bin/activate
- pip3 install -r requirements.txt
next_jobs:
script:
- source $VENV_NAME/bin/activate
- echo "hello world!"
PD:别忘了从覆盖范围或其他分析工具中排除虚拟环境目录