Triggers 无法使用Google Cloud build从cloudbuild.yaml运行Sonarqube分析

Triggers 无法使用Google Cloud build从cloudbuild.yaml运行Sonarqube分析,triggers,sonarqube,Triggers,Sonarqube,我已经将我的github repo与Google cloud build集成在一起,以便在github中每次提交后自动构建docker映像。这很好,但现在我想在Docker映像构建过程之前对代码进行分析。因此,我将sonarqube部分集成到cloudbuild.yaml文件中。但却无法运行它 我遵循了链接中提供的步骤: 并将声纳扫描仪图像放入谷歌容器注册表。 我的sonarqube服务器正在GCP实例上运行。在github中的每次提交时,CLOUD build都会自动触发并开始执行cloudb

我已经将我的github repo与Google cloud build集成在一起,以便在github中每次提交后自动构建docker映像。这很好,但现在我想在Docker映像构建过程之前对代码进行分析。因此,我将sonarqube部分集成到cloudbuild.yaml文件中。但却无法运行它

我遵循了链接中提供的步骤:

并将声纳扫描仪图像放入谷歌容器注册表。 我的sonarqube服务器正在GCP实例上运行。在github中的每次提交时,CLOUD build都会自动触发并开始执行cloudbuild.yaml文件中提到的任务

Dockerfile:

    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

如果粘贴的格式实际上与项目中的格式相匹配,那么问题在于第一个
步骤
块中的
args
属性缩进得太远:它应该与其上方的
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"

请将您的YAML内容包含在适当的格式标记中:错误表明您的YAML错误,但无法用当前格式读取。谢谢@mc1arke,格式正确。这只是打字的问题。此处PROJECT_ID表示我的实际GCP项目ID,sonarqube_url表示我的sonarqube实例的实际url。谢谢,问题得到了重新解决。