【问题标题】:How to Terminate Google cloud build job when SonarQube 7.8 quality gate check fails当 SonarQube 7.8 质量门检查失败时如何终止 Google 云构建作业
【发布时间】:2020-11-03 22:49:09
【问题描述】:

我在cloudbuild.yaml 文件中使用以下代码。但它给出了语法错误并失败了。请提出建议。

steps:
 
#build jar file 
- name: maven:3.6.1-jdk-8
  entrypoint : mvn
  args: ['package', '-q']
  dir: 'dataflows/generic/pubsub-sftp/src'
  id: 'build-jar'
  
#static code analysis by sonarqube
- name: maven:3.6.1-jdk-8
  entrypoint: bash
  args:
    - -c
    - |
      unset MAVEN_CONFIG \
      && echo "111.12.111.23 sonarqube.xxx.com" > /etc/hosts \
      && mvn sonar:sonar -q -Dsonar.login= **aa1234566789**\
      '-Dsonar.projectKey=abc' \
      '-Dsonar.projectName=ABC' \
      '-Dsonar.host.url=https://example.com' \
      '-Dsonar.qualitygate.wait=true' \
  allow_failure: true
  dir: 'dataflows/generic/pubsub-sftp/src'
  id: 'sonarqube-analysis'
  

请说明为什么会出现语法错误。 我们正在努力

【问题讨论】:

  • 请编辑您的帖子以包含您遇到的确切错误。

标签: google-cloud-platform sonarqube sonarqube-scan


【解决方案1】:

您的cloudbuild.yaml 存在一些语法问题。花点时间查看documentation 中有关语法的相关部分。特别强调处理substitutionssecretEnv variable 的方式。请注意,对于secrets you'd need to use either Cloud KMS or Secret Manager

您的cloudbuild.yaml文件的以下修改假定您已遵循relevant instructions to use Cloud KMS(以此为基础,根据您的具体环境进行所需的相关更改):

steps:
 
#build jar file 
- name: 'maven:3.6.1-jdk-8'
  entrypoint : 'mvn'
  args: ['package', '-q']
  dir: 'dataflows/generic/pubsub-sftp/src'
  id: 'build-jar'
  
#static code analysis by sonarqube
- name: 'maven:3.6.1-jdk-8'
  entrypoint: 'bash'
  args:
    - -c
    - |
      unset MAVEN_CONFIG \
      
      && mvn sonar:sonar -q -Dsonar.login=abc\
      '-Dsonar.projectKey=abc' \
      '-Dsonar.projectName=ABC' \
      '-Dsonar.host.url=https://sonarqube.home' \
      '-Dsonar.qualitygate.wait=true' \
      'allow_failure: true'
  dir: 'dataflows/generic/pubsub-sftp/src'
  id: 'sonarqube-analysis'
  
#Move jar to artifactory
- name: 'gcr.io/cloud-builders/gcloud'
  entrypoint: 'bash'
  args: ['-c', 'curl -u $$ARTIFACTORY_CREDENTIALS -X PUT "https://artifactory.build.ingka.ikea.com/artifactory/$_ARTIFACTORY_REPO/$_PACKAGE_NAME/pubsub-sftp-$BRANCH_NAME.jar" -T pipeline-bundled-0.1.jar']
  dir: 'dataflows/generic/pubsub-sftp/src/pipeline/target'  
  secretEnv: ['ARTIFACTORY_CREDENTIALS']
#Change these fields according to your configuration
substitutions:
    _ARTIFACTORY_REPO: 'your-example-value-1'
    _PACKAGE_NAME: 'your-example-value-2'
options:
    substitution_option: 'ALLOW_LOOSE'
 #Change these fields according to your configuration
secrets:
 - kmsKeyName: projects/project-id/locations/global/keyRings/keyring-name/cryptoKeys/key-name
   secretEnv:
     ARTIFACTORY_CREDENTIALS: 'encrypted-password'

【讨论】:

    猜你喜欢
    • 2020-07-14
    • 2014-07-03
    • 2016-05-18
    • 2020-07-21
    • 2020-03-19
    • 2019-09-02
    • 2017-10-26
    • 2016-03-13
    • 2021-09-12
    相关资源
    最近更新 更多