无法从 Azure Pipelines 下载包到 Azure Artifacts

Unable to download packages to Azure Artifacts from Azure Pipelines

请求您帮助连接 Azure Pipelines 的 Azure Artifact。

我的 Azure Pipeline 正在从 docker 文件构建映像,并且 'requirements' 文件包含要 pip 安装的包列表。在管道中,我使用 PipAuthenticate@1 任务对我的 Azure Artifacts 提要进行身份验证,身份验证成功,URL 作为参数传递给 docker 文件。

但是,我可以看到软件包是从外部 link 安装的,但没有下载到我的工件提要中。

工件提要 'testartifact' 当前为空,因此可以正确地转到外部 link 下载包。但我希望包随后保存在 'testartifact' 提要中,以便下一个 docker 构建,它直接从 testartifact 提要中获取包。我的假设正确吗? 如果是这样,如果我在代码中遗漏了一些东西导致包没有保存到我的工件中,你能帮忙吗?

这是 Azure Pipeline yaml 文件和 docker 文件。另附上包下载日志

感谢您的宝贵时间!

pool:
  vmImage: 'ubuntu-latest'

# Set variables
variables:
  imageversion: 1.0
  artifactFeed: testartifact

stages:
- stage: DevDeploy
  jobs:
  - job: DevBuildandPushImage
    steps:
    - bash: echo DevDeploy 
    - task: PipAuthenticate@1
      displayName: 'Pip Authenticate'
      inputs:
        artifactFeeds: $(artifactFeed)
        onlyAddExtraIndex: true

    - bash: echo "##vso[task.setvariable variable=artifactoryUrl;]$PIP_EXTRA_INDEX_URL"
    - bash: echo $PIP_EXTRA_INDEX_URL

    - task: Docker@2
      inputs:
        containerRegistry: 'testcontaineregistry'
        repository: 'testrepository'
        command: 'build'
        Dockerfile: '**/dockerfile'
        arguments: '--build-arg PIP_EXTRA_URL=$(PIP_EXTRA_INDEX_URL)'

docker文件的一部分

ARG PIP_EXTRA_URL
ENV PIP_EXTRA_INDEX_URL=$PIP_EXTRA_URL
RUN echo 'PIP_EXTRA_INDEX_URL'$PIP_EXTRA_INDEX_URL

# Install Python Packages & Requirements
COPY requirements requirements
RUN pip3 install -r requirements  --extra-index-url $PIP_EXTRA_URL 

部分日志

2020-07-16T17:39:05.0301632Z Step 8/28 : RUN echo 'PIP_EXTRA_INDEX_URL'$PIP_EXTRA_INDEX_URL
2020-07-16T17:39:05.4787725Z PIP_EXTRA_INDEX_URLhttps://build:***@XXXXXXX.pkgs.visualstudio.com/_packaging/testartifact/pypi/simple
2020-07-16T17:39:06.1264997Z Step 9/28 : COPY requirements requirements
2020-07-16T17:39:07.0309036Z Step 10/28 : RUN pip3 install -r requirements  --extra-index-url $PIP_EXTRA_URL
2020-07-16T17:39:08.3873873Z Collecting pypyodbc (from -r requirements (line 1))
2020-07-16T17:39:08.7139882Z   Downloading https://files.pythonhosted.org/packages/ea/48/bb5412846df5b8f97d42ac24ac36a6b77a802c2778e217adc0d3ec1ee7bf/pypyodbc-1.3.5.2.zip
2020-07-16T17:39:08.9900873Z Collecting pyodbc (from -r requirements (line 2))
2020-07-16T17:39:09.2421266Z   Downloading https://files.pythonhosted.org/packages/81/0d/bb08bb16c97765244791c73e49de9fd4c24bb3ef00313aed82e5640dee5d/pyodbc-4.0.30.tar.gz (266kB)
2020-07-16T17:39:09.4960835Z Collecting xlrd (from -r requirements (line 3))
2020-07-16T17:39:09.6500787Z   Downloading https://files.pythonhosted.org/packages/b0/16/63576a1a001752e34bf8ea62e367997530dc553b689356b9879339cf45a4/xlrd-1.2.0-py2.py3-none-any.whl (103kB)
2020-07-16T17:39:09.6782714Z Collecting pandas (from -r requirements (line 4))
2020-07-16T17:39:10.2506552Z   Downloading https://files.pythonhosted.org/packages/c0/95/cb9820560a2713384ef49060b0087dfa2591c6db6f240215c2bce1f4211c/pandas-1.0.5-cp36-cp36m-manylinux1_x86_64.whl (10.1MB)
2020-07-16T17:39:11.4371150Z Collecting datetime (from -r requirements (line 5))
2020-07-16T17:39:11.6083120Z   Downloading https://files.pythonhosted.org/packages/73/22/a5297f3a1f92468cc737f8ce7ba6e5f245fcfafeae810ba37bd1039ea01c/DateTime-4.3-py2.py3-none-any.whl (60kB)
2020-07-16T17:39:11.6289946Z Collecting azure-storage-blob (from -r requirements (line 6))

从任务日志中,Python 包是从外部链接恢复的。您需要确保软件包是从 Feed upstream source 安装的。然后安装后该包将存在于提要中。

步骤如下:

第 1 步:将 Python Upstream source 添加到 Feed。

第二步:使用PipAuthenticate任务获取$PIP_EXTRA_INDEX_URL

第 3 步:使用 $PIP_EXTRA_INDEX_URL 从 feed 安装包。

pip install -r requirements.txt --index-url $PIP_EXTRA_INDEX_URL

注意:步骤 2 和 3 已存在于您的 yaml 文件中。但是 pip 安装脚本似乎有问题。需要直接加上--index-url参数。

然后从 feed 上游源安装包。

在这种情况下,这些包也将存在于提要中。