Drone-Sonar scan bug push nail, as well as DroneSecret use

This follows the integration of the DroneCi installation and the Nexus3 private warehouse setup in the previous article

This chapter describes the installation of Sonar and Drone integration and push nail

1. Install Sonar

I’m doing a quick install here, so I won’t mount the configuration and install the database

docker run -d --name sonar  -p 9000:9000 -p 9092:9092 sonarqub
Copy the code

2. Generate the token

Log in to Sonar at IP :9000 and click MyAccout->Security Generate Tokens

- name: The quality of the scanning
    image: aosapps/drone-sonar-plugin
    settings:
      sonar_host: {sonar ip:port}
      sonar_token: {sonar token}
Copy the code

3. Use DroneSecret

Enter the Drone page, click Settings -> Secrets of the corresponding project, and add the ciphertextThis can be used instead, and will appear in the step log as **** (env does not work if it is not used this way).

- name: The quality of the scanning   If it is Java, it must be compiled before scanning
    image: aosapps/drone-sonar-plugin  # Image in the official plugin library
    settings:
      sonar_host: 
        from_secret: sonar_host 
      sonar_token: 
        from_secret: sonar_token
Copy the code

3. Configure sonar – project. The properties

Add a configuration file to the project root directory

Sonar. ProjectKey ={sonar. ProjectName ={sonar. ProjectName ={sonar. ProjectName ={sonar1Sonar. Sources = / drone/SRC sonar. Java. The binaries = / drone/SRC/target/classes # this to specify the compiled file directoryCopy the code

4. I didn’t find the right plugin, so I wrote a push report to the plugin

- name: Push reports to Nail  # This step is recommended at the end or before the run because the execution is fast and the data may not have been updated to Sonar
    image: yujian1996/sonar-ding:1
    environment:
      accessKey: {The accesskey nailing}
      projectKeys: {The key to the Sonar project}
      sonarUrl: {The sonar IP: port}
Copy the code

Source: github.com/NoBugBoy/So…

5. Run a container

  - name: start
    image: plugins/docker
    commands:
      - docker run -d --name test 192.16831.79.:5000/mytest/test
    volumes:
      - name: docker
        path: /var/run/docker.sock
    when:
        branch: master
        event: [ push ]    
Copy the code

6. Coverage issues

A coverage report needs to be generated if the execution discovery coverage is always 0

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.7.8</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>prepare-agent</goal>
                            <goal>prepare-agent-integration</goal>
                            <goal>report</goal>
                            <goal>report-integration</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
Copy the code

The packaging & unit testing process can be changed as follows

- name: Packaging & unit testing
    image: Maven: 3.6.2 - JDK - 8
    commands:
      - mvn clean
      - mvn org.jacoco:jacoco-maven-plugin:prepare-agent install -Dmaven.test.failure.ignore=true
      - mvn package
    volumes:
      - name: cache
        path: /root/.m2
    when:
      branch: master
      event: [ push ]
Copy the code