Azure DevOps YAML 管道矩阵策略 - [错误] 无法找到可执行文件:'bash'

时间:2021-08-01 15:22:05

标签: azure-devops

我有一个管道,我想在其中构建多个 docker 映像并将其推送到 ECR。如果我在不使用矩阵的情况下为每个服务使用任务,则一切正常,但我想通过使用带有每个服务所需变量的矩阵并行创建任务来减少构建时间:

name: Build Docker images and push to Registry

trigger:
  tags:
    include:
    - '*'

pool:
  vmImage: ubuntu-latest

variables:
- group: AWS
- name: DOCKER_REPOSITORY_URL
  value: $(AWS_ACCOUNT_ID).dkr.ecr.$(AWS_REGION).amazonaws.com
strategy:
  maxParallel: 8
  matrix:
    a-server:
      service: a-server
      path: somepath
    b-server:
      service: b-server
      path: somepath
    c-server:
      service: c-server
      path: somepath
    d-server:
      service: d-server
      path: somepath
    e-server:
      service: e-server
      path: somepath
    f-server:
      service: f-server
      path: somepath
    g-server:
      service: g-server
      path: somepath
    h-server:
      service: h-server
      path: somepath

steps:

- script: |
    aws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com
  env:
    AWS_ACCESS_KEY_ID: $(AWS_ACCESS_KEY_ID)
    AWS_SECRET_ACCESS_KEY: $(AWS_SECRET_ACCESS_KEY)
    AWS_ACCOUNT_ID: $(AWS_ACCOUNT_ID)
    AWS_REGION: $(AWS_REGION)
  displayName: 'Login to AWS'

- task: PowerShell@2
  displayName: Set last tag to variable
  inputs:
    targetType: 'inline'
    script: |
      $VERSION_TAG = git describe --tags (git rev-list --tags --max-count=1)
      Write-Host("##vso[task.setvariable variable=VERSION_TAG]$VERSION_TAG")
      Write-Host("##vso[build.addbuildtag]$VERSION_TAG")
      Write-Host($VERSION_TAG)

- task: Docker@2
  displayName: Build and Push
  inputs:
    command: buildAndPush
    Dockerfile: $(path)/Dockerfile
    buildContext: $(Build.Repository.LocalPath)
    repository: $(DOCKER_REPOSITORY_URL)/organization/$(service)
    tags: |
      $(VERSION_TAG)

错误:

Generating script.
Script contents:
aws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com
========================== Starting Command Output ===========================
##[error]Unable to locate executable file: 'bash'. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also check the file mode to verify the file is executable.

我已经浏览了其他几篇有类似问题的帖子,但不幸的是,解决方案没有帮助,并且与矩阵无关。

注意:此错误与 aws 命令无关,在调试期间,我还尝试了其他错误,甚至获取了配置文件,但同样失败了。

1 个答案:

答案 0 :(得分:1)

您在此处发出的问题来自您在矩阵配置中使用的 path 短语。例如,如果您将其更改为 imagePath,则一切都应该可以工作

strategy:
  maxParallel: 8
  matrix:
    a_server:
      service: a-server
      imagePath: somepath
    b_server:
      service: b-server
      imagePath: somepath
    c_server:
      service: c-server
      imagePath: somepath
    d_server:
      service: d-server
      imagePath: somepath
    e_server:
      service: e-server
      imagePath: somepath
    f_server:
      service: f-server
      imagePath: somepath
    g_server:
      service: g-server
      imagePath: somepath
    h_server:
      service: h-server
      imagePath: somepath
相关问题