Error in Travis Log: "You're not authorized to run analysis. Please contact the project administrator" and Travis CI org not sending Jacoco reports to SonarCloud

You are right @TomVanBraband .

I did following steps now

Step 1:

Step 2:

restart pc

Step 3 :

Again build :

But same result. do you feel something missing in my steps ?

Thanks

Hi @TomVanBraband,
Thanks for your help. i feel there is something is missing, not able to connect https://sonarcloud.io/ . i do know why it is not connecting/blocking to access sonarcloud server.

Hi @JosephThachilGeorge,

The “can not be reached” error seems to be the symptom, and the “PKIX path building failed” the underlying error -> the real problem to fix. It seems you did the necessary steps that should fix the problem related to certificates. It’s not clear to us what could be still missing here.

I would like to take a closer look, but this is an extremely busy week for me, so I don’t know when I will have the time.

I did already spent some time thinking about this thread, and I’d like to point out a few things:

  • Here we are trying to make things work using Java 8. However, running scans using Java 8 is deprecated, and will stop working later this year. So even if we get things working with Java 8, it seems a bit wasted effort. I saw you wrote you cannot install Java 11 because you need Java 8, and Tom told you this should not be an issue. You can certainly install Java 11 and also keep Java 8.
    • If you would like to keep JAVA_HOME point to Java 8 by default, that’s fine. You can override JAVA_HOME temporarily right before running the scan for this project only.
  • Your recent screenshots seem to come from tests on your computer. Ultimately I think you want to get things working on Travis CI instead. Even though running experiments locally is a really good idea in general, now that we are running to problems we cannot explain well, I think it may be a good time to re-focus our attention on getting things work on Travis CI, which is your real goal.

So based on the considerations above, I recommend to try running the scan on Travis CI using Java 11, for example openjdk11.

In fact I would take one further step back. From the very beginning of this thread, it looks like the problem is with the encrypted authentication token. We could also focus on just that. Try this on your computer first:

# Windows syntax
set TOKEN=your-sonarcloud-token
curl -sL -u "%TOKEN%:" https://sonarcloud.io/api/projects/search?organization=your-org-key-on-sonarcloud

Notice the : after %TOKEN%, it’s not a typo. The request should return a JSON text, with the list of projects in your organization. If the token is invalid, the response will contain “Insufficient privileges”.

Once you are able to get your list of projects locally, encrypt the variable on Travis CI, and run the following script for the project:

# Linux syntax
TOKEN=encrypted-sonarcloud-token
curl -sL -u "$TOKEN:" https://sonarcloud.io/api/projects/search?organization=your-org-key-on-sonarcloud

If doesn’t work, then the scan cannot work either. If this works, then you can pass it to the mvn command like this, and it should work too:

mvn verify sonar:sonar -Dsonar.login="$TOKEN"

(I notice now that you sonar.login inside the sonar.properties file before. That’s not a good idea to add secrets in version control. So the recommended practice is to pass this token on the command line, as I did above.)

Good luck, and let us know how this goes.

Hi @janos
Today i am trying to install Java 11 and try with your suggestion and will get back to you soon
Thanks a lot for your help

Hi @janos
Thanks a lot for your help. I know these days you are busy. Appreciate your hard-work.
70 % of problem has been resolved.

Below Steps has been done:
Step 1: Removed Java 1.8
Step 2: Installed Java 11
image
Step 3: Project build successfully in eclipse
Step 4: Push to GitHub
Pom has below config
image
Step 4: Pulled project in to travis ci and sonarcloude from Github

Step 5: travis.yml has below configuration:

language: java
jdk: openjdk11
sudo: required

services:

  • docker

install:

  • docker pull mongo

install: true
cache:
directories:
- $HOME/.m2
script:
- mvn -f spring-project/pom.xml -Pjacoco clean verify sonar:sonar

Result in travis:

Result in Sonar:

I have following Questions ? If possible kindly help me to find answers.

1. Dose sonarcloud prefer Java 11 rather than Java 1.8 ?
2. I tried with below option in .travis.yml for adding encrypted token:


But it did not work. Travis build was not running.
In ‘pom. xml’ file i do not want to use direct Token for Login . Is there any other option to use encrypted token?
3: My Code coverage is 97.9. Is it possible to make it 100 %
It is showing below error

It is saying “two lines are not covered by test”. Already i excluded this main class from scan
Do you have any suggestion for this issue?

Once again thanks a lot for your constant support and help.!

Hello @JosephThachilGeorge,

Great to see that you made progress!

Yes, we will completely drop support for Java 8 soon. See this announcement for more information.

Do you mean that the build failed with an unauthorized exception? In that case this points towards a wrongly encrypted value. Did you know there is a difference between travis-ci.org and travis-ci.com? Please see this guide to make sure that you are encrypting it correctly for your set-up.

Could you create a seperate topic for this issue? We’ll be happy to try to help you get to 100% coverage there.

Thanks a lot for your reply . Soon i will get back to you.

Hi @TomVanBraband,

I resolved code coverage problem! and now i have 100%

However i have problem with token :slight_smile:

Below Steps i have followed :

Step 1:

In pom i have below configuration for sonar.

image

It is worked perfectly : below is the result:

For Step 1 , Token i have taken from below location :

image

Step 1 worked perfectly!!!

Step 2:

with same token i generated secure token using following way.

Step 3:

i made change in Pom file:

I put just only below config of sonar in pom
image
Rest all sonar related configuration removed

Step 4:

Configured .travis.yml with below configuration

matrix:
include:
# always build this environment
- os: linux
dist: xenial
jdk: openjdk8
env: ADDITIONAL_MAVEN_ARGS="-Pjacoco coveralls:report"
# only on PR
- os: linux
dist: xenial
jdk: openjdk8
if: type IN (pull_request)
# only on PR or after merging a PR
- os: osx
osx_image: xcode10.1
if: type IN (pull_request) OR commit_message =~ /^Merge pull request/

addons:
sonarcloud:
organization: “josephthachilgeorge”
token:
secure: “XXXXXXXXXXXXXX” # encrypted value of your token

install: true
cache:
directories:
- $HOME/.m2
script:

  • mvn -f spring-project/pom.xml clean verify $ADDITIONAL_MAVEN_ARGS
  • mvn -f spring-project/pom.xml clean org.jacoco:jacoco-maven-plugin:prepare-agent install sonar:sonar -Dsonar.projectKey=JosephThachilGeorge_ATTSD

Result in Travis build:

Kindly let me know where i have done mistake? thanks for your help

Hi @TomVanBraband

Thanks a lot for your reply!

Below you can see my java version

Then i tried below steps

Travis result was same as shown below :

Then i made below change in .travis.yml

Then i had same result, with same error

Kindly let me know is there anything missing

Hello @JosephThachilGeorge,

It seems that we now have established that the token works when you supply it as a plain text value, however when you supply it to TravisCI with an encrypted value it fails.

This makes me sure that something went wrong during the encryption of the token.

Could you try to login before generating the token? You can do this by executing travis login and it will then ask for your credentials?

Do you confirm that you are using travis-ci.org instead of travis-ci.com? If that is not the case you have to login before generation the token by executing travis login --pro and you also have to add the --pro flag when generating the token: travis encrypt --pro SOMEVAR="secretvalue". See the documentation here.

Hi @TomVanBraband,
I am using https://travis-ci.org/
below you can see the steps that i have done

Then encrypted key i copied and pasted in travis.yml

same error has come

Hi @JosephThachilGeorge,

The SOMEVAR= in
travis encrypt SOMEVAR="secretvalue"
was just an example they used in the travis docs. In your situation you would have to use
travis encrypt VALUE_OF_TOKEN without any SOMEVAR= in the command.

Could you try that?

Hi @TomVanBraband,
I tried that as you can see below


i found same error

Hi @TomVanBraband,
Please note that above step as you suggested i run without any SOMEVAR= in the command. thanks a lot.

Please try without double-quotes around the token. (I vaguely remember something about the behavior of double-quotes in DOS shell, but I’m not sure. I think this is worth a shot.)

Hi @janos,
Thanks a lot for your reply!!!
I tried as per your suggestion without double quote

.travis.yml configured as below

matrix:
include:
# always build this environment
- os: linux
matrix:
include:
# always build this environment
- os: linux
dist: xenial
jdk: openjdk8
env: ADDITIONAL_MAVEN_ARGS="-Pjacoco coveralls:report"
# only on PR
- os: linux
dist: xenial
jdk: openjdk8
if: type IN (pull_request)
# only on PR or after merging a PR
- os: osx
osx_image: xcode10.1
if: type IN (pull_request) OR commit_message =~ /^Merge pull request/
addons:
sonarcloud:
organization: “josephthachilgeorge”
token:
secure: “key”
install: true
cache:
directories:
- $HOME/.m2

script:

  • mvn -f spring-project/pom.xml clean verify $ADDITIONAL_MAVEN_ARGS
  • mvn -f spring-project/pom.xml clean org.jacoco:jacoco-maven-plugin:prepare-agent install sonar:sonar -Dsonar.projectKey=JosephThachilGeorge_ATTSD_Project

Then Below result i got

Build is OK, however my code coverage for Sonar and coveralls become Zero

It was 100% if i configure token in pom xml

I know i am close to the solution , but something is missing

Hi @janos,

Thanks a lot for your help. Do i need to do any further steps ?

Hello @JosephThachilGeorge,

You need to point the scanner to the coverage report files that are generated by jacoco.

From your initial post I can see that you have set the property sonar.jacoco.reportPaths in your pom.xml, however this property is deprecated as you can see here. Could you try changing the property key sonar.jacoco.reportPaths to sonar.coverage.jacoco.xmlReportPaths, the value of this property should be the same as what you have set in jacoco.report.path.

Please let me know if this resolves your issue.

Hi @TomVanBraband,

Thanks a lot for your reply!
Sorry i did not understand your comments ,could you please explain little more details

my pom file is given below , what change i have to make in pom file ?

Hi @TomVanBraband
I have made below change in pom

Result was same , the code coverage is 0% in sonar