azure-devops - Azure DevOps YAML 管道矩阵策略 - [错误]无法找到可执行文件:'bash'
问题描述
我有一个管道,我想在其中构建多个 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
,在我的调试过程中,我还尝试了其他错误,甚至获取了配置文件,但同样失败。
解决方案
您在此处发出的问题来自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
推荐阅读
- iframe - 如何使用 Cypress 处理正确 iframe 的加载?
- scala - -Xlint:unsound-match 标志在 Scala 中有什么作用?
- scala - 理解 Scala 对抽象类型和类的使用
- html - 如何仅使用 CSS 为可变数量的列创建选项卡式导航
- django - Wagtail - 如何在管理表单中预先填充字段?
- vue.js - 如何动态呈现不同数据表的列表
- python-3.x - 在 Python 3 中安装 SOAPpy
- python - Python re.findall 发现奇怪的错误模式
- django - 如何在 Pycharm 中运行 Django 函数?
- r - 如何将 cat 的输出作为字符串而不是打印出来?