首页 > 解决方案 > 组合 DockerCompose@0 任务以在 Azure 管道中运行特定服务

问题描述

我有以下 azure-pipeline 来为 2 个单元测试项目运行两个 docker compose 任务。

    - task: DockerCompose@0

      displayName: 'Run Application Unit Tests'

      inputs:

        containerregistrytype: 'Azure Container Registry'

        azureSubscription: $(azureSubscription)

        azureContainerRegistry: $(azureContainerRegistry)

        dockerComposeFile: '**/docker-compose.yml'

        action: 'Run a specific service'

        serviceName: 'application.tests'

        detached: false



    - task: DockerCompose@0

      displayName: 'Run Infrastructure Unit Tests'

      inputs:

        containerregistrytype: 'Azure Container Registry'

        azureSubscription: $(azureSubscription)

        azureContainerRegistry: $(azureContainerRegistry)

        dockerComposeFile: '**/docker-compose.yml'

        action: 'Run a specific service'

        serviceName: 'infrastructure.tests'

        detached: false



    - task: PublishTestResults@2

      displayName: 'Publish test results'

      inputs:

        testResultsFormat: 'VSTest'

        testResultsFiles: '/opt/vsts/work/_temp/*.trx'

        mergeTestResults: true

        failTaskOnFailedTests: true



    - task: PublishCodeCoverageResults@1

      displayName: 'Publish coverage report'

      inputs:

        codeCoverageTool: Cobertura

        summaryFileLocation: '/opt/vsts/work/_temp/*.cobertura.xml' 

这很好用,并且结合了测试和代码覆盖结果。但是我必须在单独的任务中定义管道中的每个单元测试项目。

有没有办法在单个 azure-pipeline 任务中运行所有项目的测试?

这两个项目都在同一个解决方案 (.NET Core) 中。我知道我可以在一个项目中进行测试,但希望保持关注点分离。

标签: dockerdocker-composeazure-pipelines

解决方案


如果在compose文件中配置了多个服务,可以尝试使用Run service imagesaction。

在此处输入图像描述


推荐阅读