How to include sonarqube scan step in Google Cloud Build steps

Viewed 4834

I have a sonarqube server running on top of Azure and a CICD pipeline configured using Google cloud build on top of GCP. Do you have an idea about how to include the sonarqube connection information in my cloudbuild file as a custom build step? I'm using gradle to build my build and test my images.

2 Answers

Below sample code worked for me

#static code analysis by sonarqube
- name: 'maven:3.6.1-jdk-8'
  entrypoint: 'bash'
  args:
    - -c
    - |
      unset MAVEN_CONFIG \
      && echo "104.199.71.165 sonarqube.ct.blue.cdtapps.com" > /etc/hosts \
      && mvn sonar:sonar -q -Dsonar.login=5531b1a2d571c0482a3d45f605830e08ccf5f245 \
      '-Dsonar.projectKey=odp.df.pubsub-sftp' \
      '-Dsonar.projectName=ODP-DF-PUBSUB-SFTP' \
      '-Dsonar.host.url=https://sonarqube.ct.blue.cdtapps.com' \
      '-Dsonar.qualitygate.wait=true' \
      'allow_failure: true'
  dir: 'dataflows/generic/pubsub-sftp/src'
  id: 'sonarqube-analysis'
Related