无法使用 Google 云构建从 cloudbuild.yaml 运行 Sonarqube 分析

Unable to run Sonarqube analysis from cloudbuild.yaml with Google Cloud build

我已将我的 github 存储库与 Google 云构建集成,以便在 github 中每次提交后自动构建 docker 图像。这工作正常,但现在我想在 Docker 图像构建过程之前对代码进行声纳分析。因此,为此我将 sonarqube 部分集成到 cloudbuild.yaml 文件中。但是不能运行它。

我已按照 link 中提供的步骤进行操作:https://github.com/GoogleCloudPlatform/cloud-builders-community/tree/master/sonarqube

并将声纳扫描仪映像推送到 google 容器注册表中。 我的 sonarqube 服务器 运行ning 在 GCP 实例上。在 github 中的每次提交中,cluod build 自动触发并开始执行 cloudbuild.yaml 文件

中提到的任务

Docker文件:

    FROM nginx
    COPY ./ /usr/share/nginx/html

cloudbuild.yaml :

    steps:

    - name: 'gcr.io/PROJECT_ID/sonar-scanner:latest'
        args:
        - '-Dsonar.host.url=sonarqube_url'
        - '-Dsonar.login=c2a7631a6e402c338739091ffbc30e5e3d66cf19'
        - '-Dsonar.projectKey=sample-project'
        - '-Dsonar.sources=.'

    - name: 'gcr.io/cloud-builders/docker'
      args: [ 'build', '-t', 'gcr.io/PROJECT_ID/html-css-website', '.' ]

    images:
    - 'gcr.io/PROJECT_ID/html-css-website'

错误:

Status: Build failed
Status detail: failed unmarshalling build config cloudbuild.yaml: yaml: line 3: did not find expected key

如果您粘贴的格式实际上与项目中的格式相匹配,那么您的问题是第一个 steps 块中的 args 属性 也缩进了far: 它应该与上面的 name 属性 对齐。

--- 
steps: 
  - name: "gcr.io/PROJECT_ID/sonar-scanner:latest"
    args: 
      - "-Dsonar.host.url=sonarqube_url"
      - "-Dsonar.login=c2a7631a6e402c338739091ffbc30e5e3d66cf19"
      - "-Dsonar.projectKey=sample-project"
      - "-Dsonar.sources=."
  - name: "gcr.io/cloud-builders/docker"
    args: 
      - "build"
      - "-t"
      - "gcr.io/PROJECT_ID/html-css-website"
      - "."
images: 
  - "gcr.io/PROJECT_ID/html-css-website"