Skip to content

SonarCloud configuration

Zakhar Skaletskyi edited this page Oct 10, 2019 · 6 revisions

Travis CI setup

First need to setup “Travis CI” plugin on github project, please do next:

  1. Find in github marketplace “Travis CI” or go for link https://github.com/marketplace/travis-ci.
  2. Click on button “Set up a free trial” and choose “Open Source” price (or another one) and click on button “Install it for free”
  3. Then click on button “Complete order and begin installation”
  4. Choose “Only select repository”
  5. Click on “Select repositories” and select your repository from list.
  6. Click “Install” button
  7. At redirected page (https://travis-ci.com/) click “Sign in with GitHub” then click “Sign Up with GitHub”
  8. Click “Authorize travis-pro”
  9. On redirected page you should see name of your repository in list.

SonarCloud setup

To setup SonarCloud plugin to github project, please do next:

  1. Find in github marketplace “SonarCloud Scan” plugin or go for link https://github.com/marketplace/actions/sonarcloud-scan.
  2. Click “Use latest version”
  3. Go for link https://sonarcloud.io/
  4. Click “Log in”
  5. Select “With GitHub”
  6. Click “Analyze new project”
  7. Click “Choose an organization on GItHub”
  8. Select “Only select repositories”
  9. Click “Select repositories”
  10. Select your project from list
  11. Click “Install”
  12. Input key, or leave by default
  13. Click “Continue”
  14. Choose plan “Free plan” or another one.
  15. Click “Create organization”
  16. Click on your project from list (should be selected after clicking)
  17. Click “Set up”
  18. Below “With Travis CI” click on “Configure analysis”
  19. Click "continue"
  20. Choose Maven
  21. From point “b.Configure the scanner” copy “organization” and “Dsonar.projectKey” values to the next step.
  22. Create file “.travis.yml” in your project with next content:

.travis.yml

        language: java
        dist: trusty

        addons:  
            sonarcloud:  
                organization: "YOUR-ORGANIZATION"  
                token:  
                    secure: "YOUR-TOKEN"
        
        jdk:  
        - oraclejdk8

        script:   
        - mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install sonar:sonar -Dsonar.projectKey=YOUR-PROJECT-KEY -DskipTests=true

*If you want to run test on Travis CI, please delete next string “-DskipTests=true”. But if at least one test fail, Travis CI will build with error.

**How to get secure token will be described in next steps

  1. Go to the link https://sonarcloud.io/account/security/ or press at header on the top right icon button and select “My Account->Security”
  2. Input your login into InputForm with Text “Enter Token Name” and press button “Generate”. To see your login please go for the link https://sonarcloud.io/account
  3. Copy and insert obtained token to the “.travis.yml” file to the “secure” field.
  4. Push changes to your branch and merge with dev. For all next pull requests with included “.travis.yml” file, there will be result of Travis CI built in pull request on git and then in several minutes result of SonarCloud scanning. Bad result of build Travis CI (will be errors) means, that project can’t compile and you should fix bugs in your code.