gabrie-allaigre / sonar-gitlab-plugin

Add to each commit GitLab in a global commentary on the new anomalies added by this commit and add comment lines of modified files
GNU Lesser General Public License v3.0
713 stars 207 forks source link

baseUrl didn't work in global template #157

Closed jayxu96 closed 6 years ago

jayxu96 commented 6 years ago

Hi Gabrie, Thank you for developing this useful plugin. It works pretty good with our project.

However, I met a small problem with the template variable -- baseUrl. I want to add our sonar server's url in the global comment, so I add this in default global template You can see details on ${baseUrl}.

When I ran sonar job in pipeline, I got this error info:

Failed to create template global
freemarker.core.InvalidReferenceException: The following has evaluated to null or missing:
==> baseUrl  [in template "global" at line 3, column 26]

----
Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing</#if>. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)??
----

----
FTL stack trace ("~" means nesting-related):
    - Failed at: ${baseUrl}  [in template "global" at line 3, column 24] 

Here is my sonar job in gitlab-ci.yml:

sonar_analysis:
   stage: quality
   image: tenjaa/java-chrome-nodejs
   only:
    - master
   dependencies:
    - test_frontend 
   coverage: '/Total.*?([0-9]{1,3})%/'
   script:
    - ./gradlew sonarqube -Dsonar.host.url=$SONAR_URL 
      -Dsonar.gitlab.url=https://gitlab.com
      -Dsonar.login=$SONAR_ADMIN_USR
      -Dsonar.password=$SONAR_ADMIN_PWD
      -Dsonar.issuesReport.html.enable=true
      -Dsonar.projectVersion=0.1-SNAPSHOT#$CI_PIPELINE_ID
      -Dsonar.gitlab.project_id=$CI_PROJECT_ID 
      -Dsonar.gitlab.commit_sha=$CI_COMMIT_SHA 
      -Dsonar.gitlab.ref_name=$CI_COMMIT_REF_NAME
    - ./gradlew jacocoTestReport
   artifacts:
    name: coverage-backend
    paths:
      - backend/build/reports
   tags:
    - docker

Could you help me find what's wrong with this variable?

Thanks,

Jay

gabrie-allaigre commented 6 years ago

Hi, What is plugin version use ?

jayxu96 commented 6 years ago

Hi, our Sonarqube version is 7.2.1, the sonar-gitlab-plugin version is 3.0.0. I downloaded it in Sonar server marketplace.

gabrie-allaigre commented 6 years ago

Hi, sorry, I fixed readme,it's not baseUrl but sonarUrl

jayxu96 commented 6 years ago

Got it. Thanks.