当我在 gitlab-runner
环境中通过 tox
运行 bandit
时,与通过 tox 运行相比,它的行为有所不同
在我的 Ubuntu 环境中。
- gitlab-runner 环境 -> 递归分析项目源目录但跳过文件
- ubuntu环境 -> 递归分析项目源码目录
在ubuntu环境中运行时的调用是:tox -e bandit
在gitlab-runner环境中运行时的调用是:gitlab-runner exec docker bandit
如果是gitlab-runner环境,相关消息是([source-root-directory]
作为src
根目录) :
Files skipped (4):
[source-root-directory]/__init__.py (syntax error while parsing AST from file)
[source-root-directory]/[some-file].py (syntax error while parsing AST from file)
[source-root-directory]/[some-other-file].py (syntax error while parsing AST from file)
...
tox.ini
的相关摘录为([source-root-directory]
作为 src
根目录):
[tox]
envlist = py27, py34
[testenv:bandit]
deps = {[testenv]deps}
commands = bandit {posargs:-r [source-dir]}
.gitlab-ci.yml
的相关摘录是:
bandit:
stage: test
image: python:latest
script:
- pip install tox
- tox -e bandit
allow_failure: true
最佳答案
您应该检查两个环境中正在运行的工具和 Python 的版本是否相同。 python:latest
目前使用的是 python 3.7,而 Ubuntu 可能运行的是 2.7
关于gitlab-ci - 在 gitlab-runner 中通过 tox 运行 bandit 行为不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49921039/