无法使用Google Cloud build从cloudbuild.yaml运行Sonarqube分析 [英] Unable to run Sonarqube analysis from cloudbuild.yaml with Google Cloud build

查看:81
本文介绍了无法使用Google Cloud build从cloudbuild.yaml运行Sonarqube分析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have integrated my github repo with Google cloud build to automatically build a docker images after every commit in github. This is working fine, but now I want to do sonarqube analysis on code before Docker image building process. So for that I have integrated the sonarqube part in cloudbuild.yaml file. But not able to run it.

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

I have followed the steps provided in link: https://github.com/GoogleCloudPlatform/cloud-builders-community/tree/master/sonarqube

并将声纳扫描仪图像推送到Google容器注册表中.我的声纳服务器正在GCP实例上运行.在github中的每次提交时,都会自动触发cluod构建并开始执行cloudbuild.yaml文件中提到的任务

and pushed the sonar-scanner image in google container registry. My sonarqube server is running on a GCP instance. On every commit in github, cluod build automatically triggered and start doing task mentioned in cloudbuild.yaml file

Dockerfile:

Dockerfile:

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

cloudbuild.yaml:

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

推荐答案

如果您粘贴的格式实际上与项目中的格式匹配,那么您的问题是其中的 args 属性第一个 steps 块缩进得太远:它应该与上方的 name 属性对齐.

If the formatting you've pasted actually matches what you've got in your project then your issue is that the args property within the first steps block is indented too far: it should be aligned with the name property above it.

--- 
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"

这篇关于无法使用Google Cloud build从cloudbuild.yaml运行Sonarqube分析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆