【问题标题】:cloubuild unexpected characters '\'cloubuild 意外字符 '\'
【发布时间】:2020-09-20 23:07:47
【问题描述】:
steps:
- name: 'gcr.io/cloud-builders/gcloud'
  entrypoint: 'bash'
  args:
    - '-c'
    - |
      gcloud container images list-tags gcr.io/blah/app | grep prod | head -n 1 | awk '{print \$2}' | cut -d ',' -f 2 | awk -F. '{\$NF = \$NF + 1;} 1' | sed 's/ /./g' > version.txt

我使用 docker 和 cloudbuild 映像在本地运行它

bash -c "gcloud container images list-tags gcr.io/blah/app | grep prod | head -n 1 | awk '{print \$2}' | cut -d ',' -f 2 | awk -F. '{\$NF = \$NF + 1;} 1' | sed 's/ /./g' > version.txt"

它有效。但是当我将它发送到 cloudbuild 时,我得到了

awk: 1: unexpected character '\'
awk: 1: unexpected character '\'
awk: line 1: syntax error at or near =

【问题讨论】:

  • 尝试在您的命令中使用$$ 而不是单个$

标签: bash awk google-cloud-build


【解决方案1】:

仅使用 $$ 是不够的。您还需要删除 / 。这对我有用:

steps:
- name: 'gcr.io/cloud-builders/gcloud'
  entrypoint: 'bash'
  args:
    - '-c'
    - |
      gcloud container images list-tags gcr.io/blah/app | grep prod | head -n 1 | awk '{print $$2}' | cut -d ',' -f 2 | awk -F. '{$$NF = $$NF + 1;} 1' | sed 's/ /./g' > version.txt

【讨论】:

    猜你喜欢
    • 2017-06-13
    • 1970-01-01
    • 1970-01-01
    • 2012-03-30
    • 2014-09-08
    • 2012-09-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多