首页 > 解决方案 > Azure 管道 - 在容器中执行阶段之一

问题描述

我们的组织已开始迁移到 Azure。我们有 Azure 管道模板,可以vmImage: 'ubuntu-18.04'. 我们的计划是在模板中引入“测试”阶段并在容器中运行测试。

问题:

有人可以对此有所了解吗?

非常感谢!

标签: azureazure-pipelines-build-taskazure-pipelines-yamlazure-pipelines-tasks

解决方案


当整个管道在 vmImage 上运行时,是否可以在 Container 中运行其中一个阶段(测试)?

在 Azure Devops Yaml Pipeline 中,您可以container在作业级别指定。

然后该作业可以在目标容器上运行。

这是有关详细信息的文档。

如何从 vmImage 复制构建工件以在容器中运行测试?

在上一阶段,您可以使用Publish Build Artifacts task.

在阶段(在容器中运行作业)中,您可以使用Download Build Artifacts任务将工件下载到容器中。

最后,您可以添加测试它的步骤。

这是我的示例:

resources:
  containers:
  - container: python
    image: python:3.8
trigger:
- none

   
stages:

  - stage: artifacts
    pool:
      vmimage:  ubuntu-latest
    jobs:
      - job: test123
        steps:
        - task: PublishBuildArtifacts@1
          inputs:
            PathtoPublish: '$(Build.Sourcesdirectory)'
            ArtifactName: 'drop'
            publishLocation: 'Container'
        - script: echo $(System.ArtifactsDirectory)

  - stage: testcontainer
    jobs:
      - job: test123
        container:  python
    
        steps:
        - task: DownloadBuildArtifacts@0
          inputs:
            buildType: 'current'
            downloadType: 'single'
            artifactName: 'drop'
            downloadPath: '$(System.ArtifactsDirectory)'

        - script: |
            echo $(System.ArtifactsDirectory)
          displayName: 'Run a multi-line script'
 

注意:容器映像来自 Docker Hub、Azure 容器注册表或其他私有容器注册表。


推荐阅读