在 Google Cloud Build 中,args 数组和作为 arg 的长字符串有什么区别?

In Google Cloud Build, what is the difference between an array of args and a long string as an arg?

在设置我的构建系统以在 Cloud Registry () 中自动对我的容器进行版本控制时,我 运行 遇到了一个令人沮丧的错误。

这个有效:

- name: 'gcr.io/cloud-builders/docker'
  entrypoint: 'bash'
  args: ['-c', 'docker build -t gcr.io/$PROJECT_ID/$REPO_NAME:$SHORT_SHA -t gcr.io/$PROJECT_ID/$REPO_NAME:latest -t gcr.io/$PROJECT_ID/$REPO_NAME:$(cat VERSION) -t gcr.io/$PROJECT_ID/$REPO_NAME:$(cat SEMVER) -t gcr.io/$PROJECT_ID/$REPO_NAME:$(cat MAJOR) -t gcr.io/$PROJECT_ID/$REPO_NAME:$(cat MAJOR).$(cat MINOR) .']
images: ['gcr.io/$PROJECT_ID/$REPO_NAME']

但这不起作用:

- name: 'gcr.io/cloud-builders/docker'
  entrypoint: 'bash'
  args: ['-c', 'docker', 'build',
    '-t', 'gcr.io/$PROJECT_ID/$REPO_NAME:$SHORT_SHA',
    '-t', 'gcr.io/$PROJECT_ID/$REPO_NAME:latest',
    '-t', 'gcr.io/$PROJECT_ID/$REPO_NAME:$(cat VERSION)',
    '-t', 'gcr.io/$PROJECT_ID/$REPO_NAME:$(cat SEMVER)',
    '-t', 'gcr.io/$PROJECT_ID/$REPO_NAME:$(cat MAJOR)',
    '-t', 'gcr.io/$PROJECT_ID/$REPO_NAME:$(cat MAJOR).$(cat MINOR)',
    '.']
images: ['gcr.io/$PROJECT_ID/$REPO_NAME']

这些不应该是等价的吗?我错过了什么?

试试这个。

```
  - name: 'gcr.io/cloud-builders/docker'
    entrypoint: 'bash'
    args: 
      - -c
      - |
        docker build -t gcr.io/$PROJECT_ID/$REPO_NAME:$SHORT_SHA \
        -t gcr.io/$PROJECT_ID/$REPO_NAME:latest \
        -t gcr.io/$PROJECT_ID/$REPO_NAME:$(cat VERSION) \
        -t gcr.io/$PROJECT_ID/$REPO_NAME:$(cat SEMVER) \
        -t gcr.io/$PROJECT_ID/$REPO_NAME:$(cat MAJOR) \
        -t gcr.io/$PROJECT_ID/$REPO_NAME:$(cat MAJOR).$(cat MINOR) .

images: ['gcr.io/$PROJECT_ID/$REPO_NAME']
```

一种可行的方法是。只需从 bash 中删除入口点。

```
- name: 'gcr.io/cloud-builders/docker'
  args: [ 'build',
    '-t', 'gcr.io/$PROJECT_ID/$REPO_NAME:$SHORT_SHA',
    '-t', 'gcr.io/$PROJECT_ID/$REPO_NAME:latest',
    '-t', 'gcr.io/$PROJECT_ID/$REPO_NAME:$(cat VERSION)',
    '-t', 'gcr.io/$PROJECT_ID/$REPO_NAME:$(cat SEMVER)',
    '-t', 'gcr.io/$PROJECT_ID/$REPO_NAME:$(cat MAJOR)',
    '-t', 'gcr.io/$PROJECT_ID/$REPO_NAME:$(cat MAJOR).$(cat MINOR)',
    '.']
images: ['gcr.io/$PROJECT_ID/$REPO_NAME']
```