Sonarqube C # static code spec check (a)

Instructions for use

Code standards are also important for each development is important, say the important fact is not so important, vs simple point of code analysis can also provide a lot of advice, a little heavyweight Resharper not only provide advice, but also provides a more convenient the key to a quick refactoring tools when I need a Gitlab integrated and automated analysis time and energy each item code quality, these tools may only focus on the coding stage to the developer timely reminder, and can not meet my needs, so to find Soanrqube of this tool.

 

The following describes the installation under docker environment (partially translated from the official documentation)

1. Download image from official

Docker official mirror Description Address: https://hub.docker.com/_/sonarqube/

The following pull the latest community version 8.0 of the mirror

docker pull sonarqube:8-community-beta

You can also download the latest stable version of the default image

docker pull sonarqube

2. Get started quickly

The following Jiang to show you how to quickly run the demo instance, when you are ready to install a more stable version, please take time to read the configuration section.

docker run -d --name sonarqube -p 9000:9000 sonarqube

The default login ID is admin, password is admin

Open your browser: http: // localhost: 9000 waiting for the automatic configuration can be landed.

3. Analysis of C # code

Before analyzing the need to install sonarscanner

dotnet tool install --global dotnet-sonarscanner

Platform in creating a new project

 

 Create a token, to upload code analysis report

 

 Backup copy token generated

 

 .Net core to create a project where I created a web api project, the new script file sonar.bat

 

 sonar.bat script reads as follows:

dotnet sonarscanner begin /k:"WebTest" /d:sonar.host.url="http://localhost:9000" /d:sonar.login="40aa03b189beb63784574556e6e0c6c632668cf9"
dotnet build
dotnet sonarscanner end /d:sonar.login="40aa03b189beb63784574556e6e0c6c632668cf9"

Here are several important parameters

Red part: / k project when you create a project as a platform named

The yellow part: token is created when the project

4. Configure postgresql database sonarqube

// Get the image 
Docker pull postgresql
// start postgresql container docker run
--name db -e POSTGRES_USER=sonar -e POSTGRES_PASSWORD=sonar -e POSTGRE_DB=sonar -p 5431:5432 postgres
// 启动sonarqube docker run
--name sonar8 --link db -e SONARQUBE_JDBC_USERNAME=sonar -e SONARQUBE_JDBC_PASSWORD=sonar -e SONARQUBE_JDBC_URL=jdbc:postgresql://db:5432/sonar -p 9001:9000 sonarqube:8-community-beta

 

Examples 5.docker-compose run directly 

docker-compose.yml file contents

version: "2"

services:
  sonarqube:
    image: sonar8
    ports:
      - "9000:9000"
    networks:
      - sonarnet
    environment:
      - sonar.jdbc.url=jdbc:postgresql://db:5432/sonar
    volumes:
      - sonarqube_conf:/opt/sonarqube/conf
      - sonarqube_data:/opt/sonarqube/data
      - sonarqube_extensions:/opt/sonarqube/extensions

  db:
    image: postgres
    networks:
      - sonarnet
    environment:
      - POSTGRES_USER=sonar
      - POSTGRES_PASSWORD=sonar
    volumes:
      - postgresql:/var/lib/postgresql
      - postgresql_data:/var/lib/postgresql/data

networks:
  sonarnet:
    driver: bridge

volumes:
  sonarqube_conf:
  sonarqube_data:
  sonarqube_extensions:
  postgresql:
  postgresql_data:

 Run command

docker-compose up -d

 

Guess you like

Origin www.cnblogs.com/stealth7/p/11758151.html