首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >GCP cloudbuild.yaml条件阶跃误差

GCP cloudbuild.yaml条件阶跃误差
EN

Stack Overflow用户
提问于 2019-10-22 10:27:23
回答 1查看 2.3K关注 0票数 1

这是我的云构建文件

代码语言:javascript
复制
substitutions:
        _CLOUDSDK_COMPUTE_ZONE: us-central1-a 
        _CLOUDSDK_CONTAINER_CLUSTER: $_CLOUDSDK_CONTAINER_CLUSTER
    steps:
    - name: gcr.io/$PROJECT_ID/sonar-scanner:latest
      entrypoint: 'bash'
      args:
      - '-c'
      - 'if [ $BRANCH_NAME != 'production' ]; then sonar-scanner -Dsonar.host.url=https://sonar.test.io -Dsonar.login=${_SONAR_LOGIN} -Dsonar.projectKey=service -Dsonar.sources=. ; fi'
    - id: 'build test-service image'
      name: 'gcr.io/cloud-builders/docker'
      args: ['build', '-t', 'gcr.io/$PROJECT_ID/$REPO_NAME/$BRANCH_NAME:$SHORT_SHA', '.']
    - id: 'push test-service image'
      name: 'gcr.io/cloud-builders/docker'
      args: ['push', 'gcr.io/$PROJECT_ID/$REPO_NAME/$BRANCH_NAME:$SHORT_SHA']
    - id: 'set test-service image in yamls'
      name: 'ubuntu'
      args: ['bash','-c','sed -i "s,TEST_SERVICE,gcr.io/$PROJECT_ID/$REPO_NAME/$BRANCH_NAME:$SHORT_SHA," k8s/*.yaml']
    - id: kubectl-apply
      name: 'gcr.io/cloud-builders/kubectl'
      args: ['apply', '-f', 'k8s/']
      env:
      - 'CLOUDSDK_COMPUTE_ZONE=${_CLOUDSDK_COMPUTE_ZONE}'
      - 'CLOUDSDK_CONTAINER_CLUSTER=${_CLOUDSDK_CONTAINER_CLUSTER}'
    images: ['gcr.io/$PROJECT_ID/$REPO_NAME/$BRANCH_NAME:$SHORT_SHA']

我搞错了

失败解组构建配置cloudbuild.yaml: yaml:第17行:找不到预期的密钥

更新1

如per @cloudomation建议如果条件更新

代码语言:javascript
复制
- 'if [ $BRANCH_NAME != "production" ]; then sonar-scanner -Dsonar.host.url=https://sonar.test.io -Dsonar.login=${_SONAR_LOGIN} -Dsonar.projectKey=service -Dsonar.sources=. ; fi'

条件是工作的,但当它是真的,得到这个错误

代码语言:javascript
复制
Step #1: Digest: sha256:ef0de1c8e48544b9693b9aab2222bf849028bb66881762bf77e055b0abbf7f2b Step #1: Status: Downloaded newer image for gcr.io/wotnot-235414/sonar-scanner:latest Step #1: gcr.io/project-235414/sonar-scanner:latest Step #1: /opt/sonar-scanner-3.2.0.1227-linux/bin/sonar-scanner: exec: line 59: /opt/sonar-scanner-3.2.0.1227-linux/jre/bin/java: not found Finished Step #1 ERROR ERROR: build step 1 "gcr.io/project-235414/sonar-scanner:latest" failed: exit status 127

但是当我的脚步声是这样的时候,它就完美地工作了

代码语言:javascript
复制
- name: gcr.io/$PROJECT_ID/sonar-scanner:latest
  args:
    - '-Dsonar.host.url=https://sonar.test.io'
    - '-Dsonar.login=XXXXXXXXXXXXXX'
    - '-Dsonar.projectKey=service-name'
    - '-Dsonar.sources=.'

这也意味着在构建器映像中没有问题,这只是传递参数的问题。

代码语言:javascript
复制
docker run gcr.io/$PROJECT_ID/sonar-scanner:latest bash -Dsonar.host.url=https://sonar.test.io -Dsonar.login=${_SONAR_LOGIN} -Dsonar.projectKey=service -Dsonar.sources=.

,如果条件正常,但在那之后,条件有问题,

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-10-22 10:55:32

你应该避开引号:

代码语言:javascript
复制
  - 'if [ $BRANCH_NAME != \'production\' ]; then sonar-scanner -Dsonar.host.url=https://sonar.test.io -Dsonar.login=${_SONAR_LOGIN} -Dsonar.projectKey=service -Dsonar.sources=. ; fi'

或者使用双引号:

代码语言:javascript
复制
  - 'if [ $BRANCH_NAME != "production" ]; then sonar-scanner -Dsonar.host.url=https://sonar.test.io -Dsonar.login=${_SONAR_LOGIN} -Dsonar.projectKey=service -Dsonar.sources=. ; fi'
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58502210

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档