首页 > 解决方案 > 让 tox/pip 识别使用 Jenkins 部署的诗歌包的私有工件

问题描述

我有一个 python 包,我想使用 Jenkins 和 tox 进行测试和构建。但是,它取决于我们私人神器中的一个包。尽管诗歌正确地选择了它,但当 tox 启动时(并使用 pip 覆盖诗歌来安装依赖项),它找不到包。

我的诗歌锁定文件有

reference = "snakepit"
type = "legacy"
url = "https://our private artifactory

我的 Jenkinsfile 设置POETRY_HTTP_BASIC_PYPI_USERNAMEPOETRY_HTTP_BASIC_PYPI_PASSWORD允许在没有我的凭据的锁定文件中的 url 的情况下安装诗歌。

经过一番搜索,我似乎需要在 pyproject.toml 中扩展 legacy_tox_ini。现在看起来像:

legacy_tox_ini = """
[tox]
isolated_build = true
envlist = py36,py37,py38

indexserver =
    default = https://pypi.python.org/simple
    ourartifactory = https://{env:POETRY_HTTP_BASIC_PYPI_USERNAME}:{env:POETRY_HTTP_BASIC_PYPI_PASSWORD}@our artifactory url


[testenv]
deps =
    pytest
    pytest-cov

setenv =
    SOME_ENV={env:SOME_ENV}

commands =
    pytest tests

我还测试了将 :ourartifactory:problempackage 添加到 deps ,但这也无济于事。

如何让 pip 在此设置中识别私有工件?

标签: pythonjenkinspippython-poetry

解决方案


最后整个 indexserver 和 deps 是不必要的,一个简单的

envVar(key: 'PIP_CONFIG_FILE', value: "/pypi-artifactory/pip.conf")

在 Jenkinsfile 中就足够了。当然,这需要您的 docker 映像具有正确的 pip.conf。


推荐阅读