首页 > 解决方案 > 我正在使用 Azure Devops 构建和推送我的 Docker 映像。如何在使用 Docker 任务进行 buildAndPush 时传递参数?

问题描述

我创建了一个管道来构建 Docker 映像并将其推送到我的容器注册表。我正在使用 Docker 任务来执行此操作(buildAndPush 命令)。这是“构建和推送”步骤的 YAML 片段:

- task: Docker@2
  displayName: Build and Push
  inputs:
    command: buildAndPush
    containerRegistry: dockerRegistryServiceConnection1
    repository: contosoRepository
    tags: latest
    arguments: --label buildtype=nightly

输入arguments被任务忽略。如何将参数传递给 Docker 命令?

标签: dockerazure-devopscontinuous-integration

解决方案


buildAndPush在 Docker 任务中使用命令时,将arguments被忽略。由于这是两个 Docker 命令的组合,因此arguments输入变得不明确。

如果你想为你的构建命令添加一些参数,你可以将构建和推送分成两个单独的步骤,如下所示:

- task: Docker@2
  displayName: Build
  inputs:
    command: build
    containerRegistry: dockerRegistryServiceConnection1
    repository: contosoRepository
    tags: latest
    arguments: --label buildtype=nightly

- task: Docker@2
  displayName: Push
  inputs:
    command: push
    containerRegistry: dockerRegistryServiceConnection1
    repository: contosoRepository
    tags: latest

推荐阅读