我正在使用 Azure Devops 来构建和推送我的 Docker 映像。如何在使用 Docker 任务执行 buildAndPush 时传递参数?

Aji*_*kya 17 continuous-integration docker azure-devops

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

- task: Docker@2
  displayName: Build and Push
  inputs:
    command: buildAndPush
    containerRegistry: dockerRegistryServiceConnection1
    repository: contosoRepository
    tags: latest
    arguments: --label buildtype=nightly
Run Code Online (Sandbox Code Playgroud)

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

Aji*_*kya 44

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
Run Code Online (Sandbox Code Playgroud)

  • 他们不能有“buildArguments”和“pushArguments”吗? (8认同)