为什么Gitlab CI/CD中的烧瓶应用程序中的测试阶段失败



我正在学习GitLab CI/CD,我想在我的烧瓶应用程序上做一个阶段来运行测试。没有测试阶段,一切都可以使用Gitlab CI/CD。这是我的.gitlab-ci.yml文件:

image: python:3.8-slim-buster

cache:
paths:
- .cache/pip

stages:
- build
- test
- deploy_heroku

build message-requests:
stage: build
script:
- apt-get update
- apt-get install -y --no-install-recommends gcc
- apt install -y default-libmysqlclient-dev
- pip3 install -r requirements.txt

test message-requests:
stage: test
script:
- python3 test.py

deploy_heroku:
stage: deploy_heroku
image: ruby:latest
before_script:
- apt-get update -qy
- apt-get install -y ruby-dev
- gem install dpl
script:
- dpl --provider=heroku --app=message-requests --api-key=$HEROKU_SECRET_KEY

我的管道在测试阶段导致了这个错误:

Traceback (most recent call last):
File "test.py", line 1, in <module>
from app import app
File "/builds/dave/message-requests/app.py", line 1, in <module>
from flask import Flask
ModuleNotFoundError: No module named 'flask'
Cleaning up project directory and file based variables
00:00
ERROR: Job failed: exit code 1

本地测试运行良好。如何使用在构建阶段构建的应用程序数据?我知道在构建阶段运行test.py是可能的,但我听说最好有一个单独的测试阶段。我认为解决方案是使用工件,但我不确定它们是如何工作的,也不确定python应用程序在哪里安装所有东西。正如我所提到的,我是GitLab CI/CD的新手,因此,如果我做错了什么,我很乐意听到最佳实践。

在GitLab中,您创建的每个作业都是在一个全新的环境中开始的。因此,您必须在每个作业中安装您的需求。

您的test message-requests:作业不需要任何步骤来安装Flask或其他依赖项。您应该添加这些步骤。

最新更新