我正在尝试使用 python docker 映像在 gitlab 上运行我的剧作家 python 项目。我已经设法让它运行,但是,一旦测试套件运行,我就会使用 allure 来生成报告。这在我的个人桌面环境上运行得非常好。然而,现在我已经将它移至 gitlab,我无法在最后生成诱惑报告。
我已经附加了 gitlab 的 yaml 文件,但是当尝试运行任何 allure 命令时,它显示“allure:未找到”或“allure:未找到命令”。如果您能提供任何帮助来使其正常工作,我们将不胜感激。
image: python:3.12
variables:
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
cache:
paths:
- .cache/pip
before_script:
- python --version ; pip --version # For debugging
- pip install virtualenv
- virtualenv venv
- source venv/bin/activate
- pip install 'nodejs-bin[cmd]'
- npm install -g allure-commandline
- allure --version
- pip install -r requirements.txt # Installs the required dependencies before running
- playwright install
- playwright install-deps
- pip list # Verify the dependencies
stages: # List of stages for jobs, and their order of execution
- deploy
- generate_allure_results
- upload_results
AutomatedRegression: # Deployment and running of the feature files
stage: deploy
script:
- behave features
allow_failure: true
ParseTestResults: # Parsing test results
stage: generate_allure_results
script: "Parsing results..."
needs:
- job: AutomatedRegression
UploadResults: # Uploading results file to JIRA ticket?
stage: upload_results
script: "Some script needed here to upload test results into a Jira ticket?"
needs:
- job: ParseTestResults
看来该问题可能与 GitLab CI 环境中 Allure 命令行工具的安装或路径配置有关。您可以尝试执行以下几个步骤来解决此问题:
确保 Allure 安装正确:
npm install -g allure-commandline
命令执行成功。您可以添加检查来确认安装:
before_script:
- python --version ; pip --version # For debugging
- pip install virtualenv
- virtualenv venv
- source venv/bin/activate
- pip install 'nodejs-bin[cmd]'
- npm install -g allure-commandline
- allure --version || echo "Allure installation failed"
- pip install -r requirements.txt # Installs the required dependencies before running
- playwright install
- playwright install-deps
- pip list # Verify the dependencies
将 Allure 添加到路径:
before_script
部分来做到这一点:
before_script:
- python --version ; pip --version # For debugging
- pip install virtualenv
- virtualenv venv
- source venv/bin/activate
- pip install 'nodejs-bin[cmd]'
- npm install -g allure-commandline
- export PATH=$PATH:/root/.npm-global/bin
- allure --version
- pip install -r requirements.txt # Installs the required dependencies before running
- playwright install
- playwright install-deps
- pip list # Verify the dependencies
检查Allure安装目录:
npm root -g
并将其添加到 PATH 来找到安装目录。使用自定义 Docker 镜像: