1

My question is rather simple:

How to insert Python Code on SonarCloud with Travis-Ci?

I made the previous steps:

  • Create a project in Github
  • Assign that project in Travis-Ci
  • Create a new project analysis on SonarCloud and get the Token
  • Set up the SONAR_TOKEN as not visible and put the Token given by SonarCloud
  • In .travis.yml, add in the scripts section, the next code:

    script:
      - python setup.py test
      - ... (other possible commands)
      - sonar-scanner
    

But, when I commit something, Travis still stops me with the next job log: This is the log

I searched why on Earth this is possible, because Travis says it has sonar-scanner capabilites.

Thanks in advance and have a great day.

1 Answers1

1

You must declare sonar-scanner as plugin first in .travis.yml

addons:
  sonarcloud:
    organization: "sonarcloud_organization_key" # the key of the org you chose at step #3
    token:
      secure: ********* # encrypted value of your token
script:
  # other script steps might be done before running the actual analysis
  - sonar-scanner

from https://docs.travis-ci.com/user/sonarcloud/

Michal Polovka
  • 628
  • 1
  • 10
  • 21
  • The Token has been given as Environment Variables in the Travis-Ci page. It is necessary to put there? – José Manuel Ramos Jun 07 '18 at 12:46
  • Well, it seems so, as it isn't working :) I've always used it like in my answer and never had problem – Michal Polovka Jun 07 '18 at 12:52
  • Also, you must declare runner what is sonar-scanner in order for it to look for its configuration – Michal Polovka Jun 07 '18 at 12:54
  • You must put `- sonar-scanner -Dsonar.projectKey=PROYECT_KEY -Dsonar.sources=. -Dsonar.organization=USERNAME_GITHUB-github` In the _script_ zone Or create a sonar-project.properties with the parameters explained here: https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner – José Manuel Ramos Jun 07 '18 at 13:11