Azure管道-在容器中执行阶段之一

时间:2020-11-04 06:40:08

标签: azure azure-pipelines-build-task azure-pipelines-yaml azure-pipelines-tasks

我们的组织已开始迁移到Azure。 我们拥有Azure管道模板,该模板在vmImage: 'ubuntu-18.04'上运行检出,构建和部署阶段。 我们的计划是在模板中引入“ Test” 阶段并在Container中运行测试。

问题:

  • 当整个管道在vmImage上运行时,是否可以在Container中运行其中一个阶段(测试)?
  • 如何从vmImage复制构建工件以在Container中运行测试?

有人可以阐明这一点吗?

非常感谢!

1 个答案:

答案 0 :(得分:0)

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

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

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

这是a doc的详细信息。

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

在上一阶段,您可以使用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容器注册表或其他私有容器注册表。