Giter Club home page Giter Club logo

sonarqube-scanner's Introduction

Harness Drone/CIE SonarQube Plugin with Quality Gate

This plugin is designed to run SonarQube scans and handle the results and convert it to JUnit Format. It's written in Go and check the report results for status OK.

Main Features - v2.3.0

  • Sonar CLI updated to 6.0.0.4432
  • Execute SonarQube scans and handle the results
  • Generate JUnit reports based on the scan results
  • Quality Gate status reporting + Metrics
  • Skip Scan and only check for quality Gate Status of a specific analysisId or last analysis

Obs: USe branch and pr_key params for accuracy results matches when skiping the scan

Results

Simple Pipeline example

- step:
    type: Plugin
    name: "Check Sonar"
    identifier: run_sonar
    spec:
        connectorRef: account.DockerHubDiego
        image: plugins/sonarqube-scanner:v2.3.0
        reports:
            type: JUnit
            spec:
                paths:
                  - "SonarResults.xml"
        privileged: false
        settings:
            sonar_host: http://34.100.11.50
            sonar_token: 60878847cea1a31d817f0deee3daa7868c431433
            sources: "."
            binaries: "."
            sonar_name: sonarqube-scanner
            sonar_key: sonarqube-scanner

Full config step Example - (thanks @Ryan Nelson)

type: Plugin
spec:
    connectorRef: <+input>
    image: plugins/sonarqube-scanner:v2.3.0
    reports:
        type: JUnit
        spec:
            paths:
              - "SonarResults.xml"
    settings:
        sonar_key: <+input>
        sonar_name: <+input>
        sonar_host: <+input>
        sonar_token: <+input>
        build_number: <+input>
        branch: <+codebase.branch>
        timeout: <+input>
        sources: .
        inclusions: <+input>
        exclusions: <+input>
        level: <+input>
        showprofiling: <+input>.allowedValues("true","false"
        branchanalysis: <+input>.allowedValues("true","false")
        usingproperties: <+input>.allowedValues("true","false")
        binaries: <+input>
        sonar_qualitygate: OK
        sonar_quality_enabled: <+input>.allowedValues("true","false")
        sonar_qualitygate_timeout: <+input>
        artifact_file: <+input>
        javascript_icov_reportpath: <+input>
        java_coverage_plugin: <+input>
        jacoco_report_path: <+input>
        

Skip Scan - Pipeline example

- step:
    type: Plugin
    name: "Check Sonar Quality Gate"
    identifier: check_sonar
    spec:
        connectorRef: account.DockerHubDiego
        image: plugins/sonarqube-scanner:v2.3.0
        reports:
            type: JUnit
            spec:
                paths:
                  - "SonarResults.xml"
        privileged: false
        settings:
            sonar_host: https://sonarcloud.io
            sonar_token: 66778345yourToken817f0deee3daa7868c431433
            sonar_name: sonar-project-name
            sonar_key: sonar-project-key
            skip_scan: true

Configuration Parameters

  • key: The project key in SonarQube.
    • Example: "key": "your-project-key"
  • name: The project name in SonarQube.
    • Example: "name": "your-project-name"
  • host: The URL of the SonarQube server.
    • Example: "host": "https://sonarqube.example.com"
  • token: The token for authenticating with the SonarQube server.
    • Example: "token": "your-sonarqube-token"
  • ver: The version of the project.
    • Example: "ver": "1.0.0"
  • workspace: The workspace folder that will be passed to SonarQube CLI in case you are not cloning or scaning the /harness folder directly.
    • Example: "workspace": "/harness/subfolder"
  • branch: The branch of the project. This parameter is used to specify the branch of your codebase that the results should be matched with. If you're working on multiple branches, it's important to specify the correct branch to ensure that you're looking at the correct set of results.
    • Example: "branch": "master"
  • timeout: The timeout for the Sonar scanner.
    • Example: "timeout": "300"
  • sources: The paths for the source directories, separated by commas.
    • Example: "sources": "src"
  • inclusions: The files to be included in the analysis.
    • Example: "inclusions": "*.go, *.java"
  • exclusions: The files to be excluded from the analysis.
    • Example: "exclusions": "**/test/**/*.*,**/*.test.go"
  • level: The logging level.
    • Example: "level": "INFO"
  • showProfiling: Enable profiling during analysis.
    • Example: "showProfiling": "true"
  • branchAnalysis: Execute branch analysis.
    • Example: "branchAnalysis": "true"
  • usingProperties: Use sonar-project.properties.
    • Example: "usingProperties": "true"
  • binaries: Java binaries.
    • Example: "binaries": "/path/to/binaries"
  • quality: Quality Gate.
    • Example: "quality": "OK"
  • quality_gate_enabled: Stop pipeline if Sonar quality gate conditions are not met.
    • Example: "quality_gate_enabled": "true"
  • qualitygate_timeout: Number in seconds for timeout.
    • Example: "qualitygate_timeout": "300"
  • artifact_file: Artifact file location that will be generated by the plugin. This file will include information of Docker images that are uploaded by the plugin.
    • Example: "artifact_file": "artifact.json"
  • output-file: Output file location that will be generated by the plugin. This file will include information that is exported by the plugin.
    • Example: "output-file": "/path/to/output/file"
  • javascript_icov_reportPath: Sonar JavaScript Icov Report Path parameter.
    • Example: "javascript_icov_reportPath": "/path/to/icov/report"
  • java_coverage_plugin: Sonar Java Plugin parameter.
    • Example: "java_coverage_plugin": "jacoco"
  • jacoco_report_path: Sonar Jacoco Report Path parameter.
    • Example: "jacoco_report_path": "/path/to/jacoco/report"
  • ssl_keystore_pwd: Java Keystore Password.
    • Example: "ssl_keystore_pwd": "your-keystore-password"
  • cacerts_location: Java Truststore Location (cacerts).
    • Example: "cacerts_location": "/path/to/cacerts"
  • junit_reportpaths: JUnit Report Paths.
    • Example: "junit_reportpaths": "/path/to/junit/reports"
  • source_encoding: Source Encoding.
    • Example: "source_encoding": "UTF-8"
  • tests: Sonar Tests.
    • Example: "tests": "/path/to/tests"
  • java_test: Java Test.
    • Example: "java_test": "/path/to/java/test"
  • pr_key: Pull Request Key.
    • Example: "pr_key": "123"
  • pr_branch: PR Branch.
    • Example: "pr_branch": "your-pr-branch"
  • pr_base: PR Base.
    • Example: "pr_base": "your-pr-base"
  • coverage_exclusion: Sonar coverage exclusions.
    • Example: "coverage_exclusion": "**/test/**/*.*,**/*.test.go"
  • java_source: Sonar Java source.
    • Example: "java_source": "1.8"
  • java_libraries: Sonar Java libraries.
    • Example: "java_libraries": "/path/to/libraries"
  • surefire_reportsPath: Sonar surefire reportsPath.
    • Example: "surefire_reportsPath": "/path/to/surefire/reports"
  • typescript_lcov_reportPaths: Sonar TypeScript lcov reportPaths.
    • Example: "typescript_lcov_reportPaths": "/path/to/typescript/lcov/reports"
  • verbose: Sonar verbose.
    • Example: "verbose": "true"
  • custom_jvm_params: JVM parameters. Use comma for multiple parameters.
    • Example: "custom_jvm_params": "-Dsonar.java.source='value_you_want'"
  • taskid: Sonar analysis taskId.
    • Example: "taskid": "your-task-id"
  • skip_scan: Skip Sonar analysis scan - get last analysis automatically.
    • Example: "skip_scan": true

Detail Informations/tutorials Parameteres: DOCS.md.

Build Process

build go binary file:

GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o sonarqube-scanner

build docker image

docker build -t plugins/sonarqube-scanner .

Testing the docker image:

docker run --rm \
  -e DRONE_REPO=test \
  -e PLUGIN_SOURCES=. \
  -e SONAR_HOST=http://localhost:9000 \
  -e SONAR_TOKEN=60878847cea1a31d817f0deee3daa7868c431433 \
  -e PLUGIN_SONAR_KEY=project-sonar \
  -e PLUGIN_SONAR_NAME=project-sonar \
  plugins/sonarqube-scanner

Plugin Configuration

Console Results

sonarqube-scanner's People

Contributors

diegopereiraeng avatar renovate[bot] avatar renovate-bot avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.