0

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.

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

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:

    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'

Error:

Status: Build failed
Status detail: failed unmarshalling build config cloudbuild.yaml: yaml: line 3: did not find expected key
mc1arke
  • 1,030
  • 10
  • 22
Ankit Soni
  • 95
  • 2
  • 13
  • Please enclose your YAML content in appropriate formatting tags: the error indicates your YAML is wrong but it's impossible to read it with the current formatting. – mc1arke Jul 18 '19 at 07:22
  • Thanks @mc1arke , The formatting was correct. It was just typing issue here. Here PROJECT_ID indicates my actual GCP project id and sonarqube_url iindicates the actual url of my sonarqube instance – Ankit Soni Jul 19 '19 at 09:19
  • @AnkitSoni Hi. May I ask regarding "My sonarqube server is running on a GCP instance." is your instance on private or public netowork? Is it reachable from the internet? – Yannis Mar 17 '22 at 07:27

1 Answers1

1

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"
mc1arke
  • 1,030
  • 10
  • 22