Sonarcloud is not authorized using Travis CI and Maven - java

I have an experimental project on my Github used for the practising the CI service integrations. I struggle with using Sonarcloud.
I have followed both Tavis CI + Sonarcloud tutorial and Maven example. Mz first confusion starts with the token and properties file whereas the first source suggests creating sonar-project.properties file and the Maven example source does not have any. Here where the documentation is very unclear.
I ignored the properties file and I have done the following steps:
Generated token on sonarcloud.io for my project: e53.....239
Encrypted token on travis-encrypt.github.io since it's the most comfortable way for a Windows user. The 2 following inputs resulted in g3s.....+Q=:
NicharNET/Gistintex
SONAR_TOKEN="e53...239" - I tried both to wrap between quotation marks and without.
Added to Settings -> Environment variable key SONAR_TOKEN with the value of the generated Sonarcloud token e53...239.
Completed travis.yml with the secure token:
language: java
sudo: false
jdk: oraclejdk8
addons:
sonarcloud:
organization: "nicharnet-github"
token:
secure: "g3sLTdS597mklh1I9HgXr71NRCiOk2n9I41PL2wklnAidwibfocyEcWvSQxjmbhNTjdrcW0cAfzh73Ago8hwfdloraryDY9Ng9L1runxayShtPOqZMPI6nz8zUwLaDfqJVwXWv6A3xICOMFl0UhvF351GPErHhrUO7YIa8el3kESeotYy7kkTzeQ7BA239y7EVFw8H4OCW2gjP2G/InxKnlXfNjgQA3GsnZdJ3uWO3No5kwt5ybfuCCV42cp/UczLIzNbo0RW9Z9jBl5IFMzJaUQUfWV3Pp5QEPmpB7Anr/4W1EtjJPjpSIC/+jBmbrkvC/CSzzTPjaH9LzEQ5m4F5JpRw01blqgKH/153qfs1jRgZK6WVRuhe7yAATHCO/IM0DM+kC0mUJTcXKyv9pRm93E4wp+KzdHYy0LdA83wFgMmvlB8pcm20ImAe7B2SBFx5TGtETa6ea6k2BS+DfBXe6sLBnrl1zZB8nxCDnYiwT1BJFxizgv3EJ6Krjd3cSSxr6PGnXDD/yTeFNJarpMbA+wR6AQetJ89LiDBXYiw6GPgWk/A4vUDIsIaXGqCpydeZHkr2ufS1Ap4yYS0Um2GeDeQXTsBTSCg7BViFgduUI1NPYT1avKg7b64nsdpdjBVofOvzJsgiT66WlaJmt23BUCJsnmXwwEcW1387b4G+Q="
script:
- mvn clean install org.jacoco:jacoco-maven-plugin:prepare-agent sonar:sonar
Committed and pushed changes into the repository and Travis CI started to work and resulted in:
Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.4.1.1168:sonar (default-cli) on project gistintex: Not authorized. Please check the properties sonar.login and sonar.password.
The error could be found on my Travis CI build. What do I do wrong?
I have skimmed through Error using Travis CI with Sonarcloud: Not authorized. Please check the properties sonar.login and sonar.password SO question and Travis CI Sonarqube analysis article, which unfortunately didn't help me though. My GitHub project source.
I have tried to add these plugins to pom.xml and run the analysis locally:
org.codehaus.mojo: sonar-maven-plugin: 5.1
org.sonarsource.scanner.maven: sonar-maven-plugin: 3.4.1.1168
Running this on my machine resulted in the correct Sonarcloud analysis:
mvn sonar:sonar \
-Dsonar.organization=nicharnet-github \
-Dsonar.host.url=https://sonarcloud.io \
-Dsonar.login=e53.....239
However, my goal is to run the analysis after every committed version using Travis CI. I am sure I have done wrong the key encryption but I can't figure what exactly.

The key encryption problem usually happens when you execute the generation without the login command against travis.com instead of travis.org
In order to run on every commit you could connect your repo with SonarCloud Scan, generate a secret in your sonarcloud.io project page and there you will find instructions to modify your .travis.yml
if you use travis.org
travis encrypt <YOUR_SONAR_SECRET>
if you use travis.com
travis login --pro
then generate your token like this:
travis encrypt --pro <YOUR_SONAR_SECRET>
finally you need to add your pipeline instruction to your .travis.yml file
Check in your Travis CI repo settings when it should be triggered
here some related links:
Error using Travis CI with Sonarcloud: Not authorized. Please check the properties sonar.login and sonar.password
https://docs.travis-ci.com/user/encryption-keys/#usage
https://github.com/marketplace/actions/sonarcloud-scan
https://sonarcloud.io/documentation/integrations/github/

Related

'com.android.application', version: '7.1.3', apply: false was not found in any of the following sources:

I'm new to Android studio. The first time I created a new project the IDE started downloading gradle, and afterwards it started to download com.android.application . this part took a lot of time but after some minutes I got this error :
Plugin [id: 'com.android.application', version: '7.1.3', apply: false] was not found in any of the following sources:
* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Exception is:
org.gradle.api.plugins.UnknownPluginException: Plugin [id: 'com.android.application', version: '7.1.3', apply: false] was not found in any of the following sources:
- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (could not resolve plugin artifact 'com.android.application:com.android.application.gradle.plugin:7.1.3')
Searched in the following repositories:
Gradle Central Plugin Repository
Google
MavenRepo
My Android studio version is bumblebee 2021.1.1 patch 3. And I have tried the following:
https://stackoverflow.com/a/71784769/18031488
https://stackoverflow.com/a/72799441/18031488 (I tried a proxy. didn't solve the problem)
https://stackoverflow.com/a/71786490/18031488
https://stackoverflow.com/a/71020686/18031488
https://stackoverflow.com/a/44403912/18031488
https://stackoverflow.com/a/71097021/18031488
Can I install the plugin manually or is there any way to get rid of this?
I had the same problem. Sitting behind a company Zscaler Web Gateway terminating all TLS traffic. None of the proposed actions like adding a proxy or other repos, or changing IPv4/IPv6 settings worked.
The solution was:
add the Zscaler certificate to Android Studio's JRE cacert keystore. You find it under \jre\lib\security\cacerts.
Either use the Java keytool \jre\bin\keytool.exe from a Command windows / Shell or a GUI like KeyStoreExplorer. Default password of the keystore is "changeit".
After adding the proxy certificate to cacerts, restart AS and now the gradle project build works!
Note: In case your Company security apps are scanning all downloaded stuff, sometimes they can't do that fast enough and you get 403 errors in your IDE for Gradle/Maven sync actions. Repeating the project sync process normally eliminates such errors.

Jenkins + Maven release plugin: release:branch + Git - Unable to commit files

I'm trying to make a release using the Maven release plugin, but I get an error
[ERROR] Command output:
[ERROR] GitLab: The project you were looking for could not be found.
[ERROR] fatal: The remote end hung up unexpectedly
In my pom.xml such settings:
<scm>
<developerConnection>scm:git:ssh://git#git.domain.ua/myproject/mylib.git</developerConnection>
<url>https://git.domain.ua/myproject/mylib</url>
<tag>HEAD</tag>
</scm>
My Jenkins job settings:
Repository URL: ssh://git#git.domain.ua/myproject/mylib.git
Credentials: my ssh-key also imported in Git repo as deploy key
Branch Specifier (blank for 'any'): */development
Maven Release goals and options: -Dresume=false release:branch javadoc:javadoc
DryRun goals and options: -Dresume=false -DdryRun=true release:prepare
As you can see from the logs, Git-plugin successfully clones a branch, but Maven cannot make a commit for some reason:
Cloning the remote Git repository
Cloning repository ssh://git#git.domain.ua/myproject/mylib.git
> git init /opt/jenkins/workspace/MYJOB # timeout=10
Fetching upstream changes from ssh://git#git.domain.ua/myproject/mylib.git
> git --version # timeout=10
using GIT_SSH to set credentials JENKINS(jenkins user with jenkins#USER)
git checkout development
Switched to a new branch 'development'
Branch development set up to track remote branch development from origin.
Parsing POMs
Established TCP socket on 44626
[INFO] Executing: /bin/sh -c cd /opt/jenkins/workspace/MYJOB && git push ssh://git#git.domain.ua/myproject/mylib.git refs/heads/development:refs/heads/development
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.5.1:branch (default-cli) on project MYPROJECT: Unable to commit files
[ERROR] Provider message:
[ERROR] The git-push command failed.
[JENKINS] Archiving /opt/jenkins/workspace/MYPROJECT/pom.xml to *****-SNAPSHOT.pom
[ERROR] Command output:
[ERROR] GitLab: The project you were looking for could not be found.
[ERROR] fatal: The remote end hung up unexpectedly
I guess Maven doesn't know anything about the key that uses the Git-plugin, but I can't figure out how to configure the Maven Release Plugin to use the same key?
Try doing this in your Jenkins job configuration:
Update the Branch Specifier (blank for 'any') to the syntax refs/heads/development.
Under SCM > Git > Additional Behaviours, select Checkout to specific local branch and then enter ** as the branch name.
Under Build Environment, select SSH Agent > Specific credentials, and then specify the same SSH key that you used for cloning the repository.
The error is in the clone via https protocol and the push via ssh protocol. You must define which protocol to use for the transfer. For comparison, use the result of the command: git remote show origin, with the scm parameter set in the pom.xml file.
Example:
<scm>
<connection>scm:git:git#github.com:user/repo-name.git</connection>
<developerConnection>scm:git:git#github.com:user/repo-name.git</developerConnection>
<url>git#github.com:user/repo-name.git</url>
<tag>HEAD</tag>
</scm>
try to remove the ssh:// and just use : scm:git:git#git.domain.ua/myproject/mylib.git
replace the url tag by a connection tag with the value : scm:git:git#git.domain.ua/myproject/mylib.git
In the end it's gonna be something like this :
scm:git:git#git.domain.ua/myproject/mylib.git
scm:git:git#git.domain.ua/myproject/mylib.git
Also the plugin is searching for a project "MYPROJECT" uppercase , or i guess in gitlab youhave "myproject", you can check and change all "MYPROJECT " reference to "myproject" and then try again.
Best regards,

Permission error when using Snyk for gradle wrapper in GitLab

I am trying to integrate Snyk into my GitLab CI pipeline. I install it with npm, authenticate with my personal token and run snyk test. I get the following error which prevents me from getting the results:
Testing /builds/User/pipeline...
Downloading https://services.gradle.org/distributions/gradle-4.5-all.zip
................................................................................
Unzipping /root/.gradle/wrapper/dists/gradle-4.5-all/cg9lyzfg3iwv6fa00os9gcgj4/gradle-4.5-all.zip to /root/.gradle/wrapper/dists/gradle-4.5-all/cg9lyzfg3iwv6fa00os9gcgj4
Set executable permissions for: /root/.gradle/wrapper/dists/gradle-4.5-all/cg9lyzfg3iwv6fa00os9gcgj4/gradle-4.5/bin/gradle
ERROR: Job failed: exit code 1

Running tests on travis using mysql

I've been trying for the last week or so to make integration tests work on travis for a school project. I've debugged a fair bit of the project but now I'm blocked and need external help.
To give a bit of context, so far, I've debugged the java project so that the tests can be launched from eclipse or from maven in command line. I've worked on the travis file so that a database is created, the database scripts run and the java tests launch. However, the tests fail on travis because of a "table missing" in the database.
This is a link to our repo.
This is the travis.yml file's code:
language : java
jdk:
- oraclejdk8
service:
- mysql
before_script:
- mysql -e 'DROP DATABASE IF EXISTS koalatest'
- mysql -e 'CREATE DATABASE IF NOT EXISTS koalatest;'
- mysql -u root --default-character-set=utf8 koalatest < backend/koalacal-backend/koalacal.sql
script: cd backend && cd koalacal-backend && mvn test -X
after_success:
- bash <(curl -s https://codecov.io/bash)
The java project that is being built and run by maven is located under rootfolder -> backend -> koalacal-backend.
Here is a link to the error log maven produces on travis.
This line seems to be the source of the error:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'koalatest.Calendar' doesn't exist
I have two hypothesis:
1- The sql script that creates all the tables is not being run properly by travis.
To test this hypothesis, I changed the name of the script called by travis. As expected, I got an error saying that travis can't find the file. So at least, I know that this line of code causes travis to look up at an sql file.
- mysql -u root --default-character-set=utf8 koalatest < backend/koalacal-backend/koalacal.sql
That being said, I have no idea if the file is run properly on the database.
For the sake of putting all relevant informations in this post, here is a link to the database script.
2- The tests can't connect properly to the database.
Here is the config file that contain the info regarding which database to connect to:
TestInstance=true
user=root
password=
serverName=localhost
databaseName=koalacal
portNumber=3306
testUser=root
testPassword=
testServerName=127.0.0.1
testDatabaseName=koalatest
testPortNumber=3306</code>
If the parameter TestInstance is set to true, the tests take the informations testUser, testPassword, testServerName, testDatabaseName and testPortNumber to connect to the relevant database.
I believe the connection informations currently contained in the config file match how the travis documentation says we need to connect to a mysql database. I tried to change the testUser to something invalid (like root3) and got error messages as expected.
Maybe somehow the tests can't connect to the database and don't produce a related error message, but I doubt it.
Can someone look at my problem and see if I've missed something obvious (or not)? I don't know what else to try and I don't want to be blocked one more week on a technical issue.
For anyone who may google travis mysql and has a similar error to the one I had, I solved my problem.
The error was caused by a case sensitivity issue. The java code tried to connect to tables like 'Calendar' and 'Event' while the sql script created the tables 'calendar' and 'event'.
It took a long time to troubleshoot this because the case sensitivity didn't pose any problem on my machine. Maven can run its tests properly without any issue. It's only on the travis servers that case sensitivity of the tables started to matter.

Error when push Liberty for Java application in IBM Bluemix

when I run sample IBM Bluemix Liberty for Java application https://github.com/ibmjstart/bluemix-java-postgresql-uploader.git following error:
-----> Downloaded app package (1.9M)
-----> Downloaded app buildpack cache (4.0K)
OK
/var/vcap/packages/dea_next/buildpacks/lib/buildpack.rb:101:in build_pack': Unable to detect a supported application type (RuntimeError) from /var/vcap/packages/dea_next/buildpacks/lib/buildpack.rb:74:inblock in compile_with_timeout'
from /usr/lib/ruby/1.9.1/timeout.rb:68:in timeout' from /var/vcap/packages/dea_next/buildpacks/lib/buildpack.rb:73:incompile_with_timeout'
from /var/vcap/packages/dea_next/buildpacks/lib/buildpack.rb:54:in block in stage_application' from /var/vcap/packages/dea_next/buildpacks/lib/buildpack.rb:50:inchdir'
from /var/vcap/packages/dea_next/buildpacks/lib/buildpack.rb:50:in stage_application' from /var/vcap/packages/dea_next/buildpacks/bin/run:10:in'
FAILED
Server error, status code: 400, error code: 170001, message: Staging error: cannot get instances since staging failed
TIP: use 'cf logs jpu-henryhan --recent' for more information
The top error looks like you left off the -p <path_to_war> parameter when doing a push. If you just push a directory containing a WAR file, it will not be detected by the Java buildpack.
The tip provided in the output of your cf push request is relevant.
TIP: use 'cf logs jpu-henryhan --recent' for more information
Running that command will tail the log files produced during the staging process and let you see what error may have been raised. Often, it can be a missing dependency or a transient failure of some sort.
I just successfully deployed the sample using the "deploy to Bluemix" button and manually via the cf command line tool. Unless you changed the code, it is most likely that this error is a transient failure.
Run following command:
$ cf push jpu- -b https://github.com/cloudfoundry/java-buildpack --no-manifest --no-start -p PostgreSQLUpload.war
add the parameter to set the buildpack "-b https://github.com/cloudfoundry/java-buildpack"

Categories