【问题标题】:Unable to download packages to Azure Artifacts from Azure Pipelines无法从 Azure Pipelines 将包下载到 Azure Artifacts
【发布时间】:2020-11-06 11:45:41
【问题描述】:

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

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

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

工件提要“testartifact”当前为空,因此它可以正确地转到外部链接以下载包。但我希望该包随后保存在“testartifact”提要中,以便下一个 docker build 直接从 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)'

dockerfile 的一部分

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))

【问题讨论】:

    标签: azure azure-devops azure-artifacts azure-pipelines-yaml


    【解决方案1】:

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

    步骤如下:

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

    Step2:使用PipAuthenticate任务获取$PIP_EXTRA_INDEX_URL

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

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

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

    然后从 feed 上游源安装软件包。

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

    【讨论】:

    • 非常感谢!我将 docker 文件中的语句修改为 RUN pip3 install -r requirements --index-url $PIP_EXTRA_URL 并解决了问题
    猜你喜欢
    • 1970-01-01
    • 2021-01-05
    • 1970-01-01
    • 1970-01-01
    • 2019-11-08
    • 1970-01-01
    • 2020-01-30
    • 2020-03-27
    • 1970-01-01
    相关资源
    最近更新 更多