Jesus Vidal
Jesus Vidal

Reputation: 445

Azure DevOps YAML pipeline matrix strategy - [error]Unable to locate executable file: 'bash'

I have a pipeline where I want to build and push several docker images to ECR. Everything works fine if I use a task for each service without using a matrix, but I want to reduce the build time by parallel creating the tasks using a matrix with the variables each service needs:

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)

Error:

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.

I already went through several other posts with similar issues, but solutions, unfortunately, did not help and were not matrix-related.

Note: This error is not isolated to aws command, during my debug I also tried others, even sourcing the profile, but it fails with the same.

Upvotes: 0

Views: 744

Answers (1)

Krzysztof Madej
Krzysztof Madej

Reputation: 40553

You issue here comes from path phrase which you use in matrix configuration. If you change it to imagePath for instance all should work

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

Upvotes: 3

Related Questions