Run sonarqube scanner with gitlab ci

前端 未结 2 1574
猫巷女王i
猫巷女王i 2021-02-04 20:30

I am trying to put together a CI environment for a .NET application using the following stack (just the relevant ones):

  • Debian + mono
  • Docker
  • Gitl
2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-04 21:23

    You need to install sonar-scanner first. You can find portage of sonar-scanner for almost any recent language, for example for npm you don't have to use directly the java executor:

    I only add to do this :

    npm install --save sonar-scanner
    

    Then I needed to add this in my package.json

    "scripts": {
      "sonar-scanner": "node_modules/sonar-scanner/bin/sonar-scanner"
    }
    

    This is my job in .gitlab-ci.yml:

    job_testmaster:
      stage: test
      script:
        - PACKAGE_VERSION=$(node -p "require('./package.json').version")
        - echo sonar.projectVersion=${PACKAGE_VERSION} >> sonar-project.properties
        - npm run build
        - npm run sonar-scanner -- -Dsonar.login=${SONAR_LOGIN}
      only:
        - master
      tags:
        - docker
    

    With this, I am able to start sonar analysis, but I am not able to use the quality gates after.

    Hope this help.

提交回复
热议问题