【发布时间】:2021-06-16 04:05:13
【问题描述】:
我一直在尝试运行 Jenkins 作业(用于 python3 标签),但在 linting 和 testing 阶段失败。以下是每个阶段的详细信息:
linting : 这个阶段会触发 Makefile 目标 make lint,它会尝试在我项目中的所有 python 文件上运行 pylint。
即pylint $(shell find -type f -name "*.py")
测试: 这个阶段会触发 Makefile 目标 make test,它会尝试对我项目中的所有文件运行 pytest。
即pytest --cov=. --cov-report=term --cov-report=html --cov-fail-under=95 my_project
上述两个阶段都需要在 Jenkins 中进行一些预安装或 virtualenv 设置,才能识别命令 pylint 和 pytest。
我尝试通过指定 virtualenv 路径来设置它,然后为所有必需的包运行pip install,如下所示:
Jenkins 文件:
stage("linting") {
steps {
withEnv(["HOME=${env.WORKSPACE}", "PATH+PIP=${env.WORKSPACE}/.local/bin"]) {
sh "make lint-code"
}
}
}
生成文件:
lint-code:
pip install --upgrade pip
pip install -r requirements.txt
@pylint $(shell find -type f -name "*.py")
requiremnts.txt
pylint
pytest
我收到 make: pylint: Command not found Makefile:5: recipe for target 'lint' failed 或 make: pylint: Command not found Makefile:5: Error [127]
此外,即使在 Jenkins 阶段传递 $PATH 后,它也没有设置,因此出现以下错误:
The scripts py.test and pytest are installed in '/home/ubuntu/workspace/my_project_PR-56/.local/bin' which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
【问题讨论】:
-
你不应该在配方中使用 make 的
$(shell ...)函数。您的配方已经在 shell 中运行,不需要它,它可能会导致令人困惑的行为,因为它先扩展,然后再扩展配方的其余部分。请改用 shell 语法,例如$$(find -type f -name "*.py")
标签: python python-3.x jenkins makefile jenkins-pipeline