使用 Gitlab CI 运行程序获取错误"cannot import name 'run_cli' from 'robot'"



我有一个类似python -m robot --include staging_lp_items的机器人命令,它在我的系统中运行得很好。

当尝试在服务器机器中使用GitLab runner(作为阶段脚本)运行此程序时,显示以下错误:

Traceback (most recent call last):
File "/usr/local/lib/python3.9/runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/usr/local/lib/python3.9/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/usr/local/lib/python3.9/site-packages/robot/__main__.py", line 25, in <module>
from robot import run_cli
ImportError: cannot import name 'run_cli' from 'robot' (/usr/local/lib/python3.9/site-packages/robot/__init__.py)

我还确保安装robot,在主脚本和服务器环境上安装robot之前返回pip list,以及requirements.txt文件中的其他要求。以下是系统配置:

$ cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye

GitLab Yaml:

stages:
- build
- build_branch
- test
variables:
REGISTRY_IMAGE: ${CI_REGISTRY}/qa/${CI_PROJECT_NAME}
GIT_IMAGE: ${CI_REGISTRY}/qa/${CI_PROJECT_NAME}

build:
image: docker:latest
stage: build
before_script:
- docker login -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD} ${CI_REGISTRY}
script:
- echo image name $REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
- docker build -t $REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG .
- docker push $REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
rules:
- when: manual

build_branch:
image: docker:latest 
stage: build_branch
before_script:
- docker login -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD} ${CI_REGISTRY}
script:
- echo project image is ${GIT_IMAGE}
- docker build --build-arg CI_COMMIT_REF_NAME=master -t $GIT_IMAGE:$CI_COMMIT_REF_NAME .
- docker push $GIT_IMAGE:$CI_COMMIT_REF_NAME
rules:
- when: manual
allow_failure: true
run_test:
image: $GIT_IMAGE:$CI_COMMIT_REF_NAME
stage: test
script:
- cat /etc/os-release
- chmod +x ./.deploy/run-test.sh
- ./.deploy/run-test.sh
rules:
- when: manual
allow_failure: false

共有三个阶段,buildbuild_branch工作良好。最后一个是我遇到问题的主要阶段。这个阶段将运行(eval)run-test.sh,它有一个我之前提到的简单的python robotframework命令。

Python版本:3.9

Dockerfile

FROM python:3.9
ARG CI_COMMIT_REF_NAME=master
COPY . .
RUN pip install [Repository]
RUN pip install -r requirements.txt

您的requirementst.txt无效。你有robothttps://pypi.org/project/robot/,而要使用的库名为robotframeworkhttps://pypi.org/project/robotframework/.

在requirements.txt中将robot重命名为robotframework

最新更新