I've successfully setup a project which uses Travis CI to for builds and tests. Now I'm trying to add Coverity Scan.
I created a branch called coverity_scan and set it be used for coverity builds. After I push a commit to this branch I can see in Travis CI build console that Coverity tool starts doing its job:
Coverity Scan analysis selected for branch coverity_scan.
Coverity Scan analysis authorized per quota.
...
Running Coverity Scan Analysis Tool...
The Travis build succeeds and in Coverity build-log.txt file I see this:
2016-10-06T21:02:39.132946Z|cov-build|2665|info|>
2016-10-06T21:02:39.132946Z|cov-build|2665|info|> Build time (cov-build overall): 00:01:36.812431
2016-10-06T21:02:39.132946Z|cov-build|2665|info|>
2016-10-06T21:02:39.134719Z|cov-build|2665|info|> Build time (Java emits total): 00:01:07.595656
2016-10-06T21:02:39.134719Z|cov-build|2665|info|>
2016-10-06T21:02:39.134719Z|cov-build|2665|info|>
2016-10-06T21:02:39.134763Z|cov-build|2665|info|> Emitted 30 Java compilation units (100%) successfully
2016-10-06T21:02:39.134763Z|cov-build|2665|info|> [WARNING] Recoverable errors were encountered during 1 of these Java compilation units.
2016-10-06T21:02:39.134763Z|cov-build|2665|info|>
2016-10-06T21:02:39.134763Z|cov-build|2665|info|> 30 Java compilation units (100%) are ready for analysis
2016-10-06T21:02:39.134763Z|cov-build|2665|info|> For more details, please look at:
2016-10-06T21:02:39.134763Z|cov-build|2665|info|> /home/travis/build/Edvinas01/chat-rooms/server/cov-int/build-log.txt
However after this finishes, I do not see any submitted builds or changes in projects Coverity dashboard. The project status stays on pending.
I've followed this guide and setup my .travis.yml file like this:
language: java
jdk:
- oraclejdk8
before_script:
- cd server
- chmod +x gradlew
script:
# Run tests when not on coverity branch.
- if [ ${COVERITY_SCAN_BRANCH} != 1 ]; then
./gradlew check;
fi
cache:
directories:
- ~/.gradle
after_success:
# Upload coveralls when not on coverity branch.
- if [ ${COVERITY_SCAN_BRANCH} != 1 ]; then
./gradlew cobertura coveralls;
else
cat cov-int/build-log.txt;
fi
notifications:
email:
on_success: change
env:
matrix:
- TERM=dumb
global:
# COVERITY_SCAN_TOKEN
- secure: "<TOKEN>"
before_install:
- echo -n | openssl s_client -connect scan.coverity.com:443 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | sudo tee -a /etc/ssl/certs/ca-
addons:
coverity_scan:
project:
name: "Edvinas01/chat-rooms"
description: "Build submitted via Travis CI"
notification_email: "<EMAIL>"
build_command_prepend: "./gradlew clean"
build_command: "./gradlew build"
branch_pattern: coverity_scan
Do I have to specify some additional configuration so that my Coverity builds get published?
Got some time and created a virtual machine with java and the coverity analysis tool. After pulling my project and running the tool I noticed this in the logs:
[WARNING] No files were emitted. This may be due to a problem with your configuration
or because no files were actually compiled by your build command.
After fiddling quite a bit and looking at other projects, I found out that this was due to Gradle version. My project was using 3.0 so I downgraded to 2.14.1 and it finally seems to be working.
For what is worth, there is no issue with using Coverity with any Gradle version, as long as you make sure you are not using the daemon (just to be sure you may specify --no-daemon on the command line).
That said, there are a number of other easy to miss gotchas, resulting in not-quite-obvious error messages.
For useful background, see Caleb's answer here:
Can't get Coverity Scan to work (Java/Kotlin/Gradle 3.3 on Windows and Travis)
For working example, you may refer to this project:
https://github.com/ddimtirov/nuggets
Related
I try to CI/CD for the jave open source project, which is hosted on github.
When I build the project with maven local, then it works just fine.
But the same maven build fails when triggered inside the github/gitaction environment when building the jave-core target.
https://github.com/a-schild/jave2/blob/develop/jave-core/pom.xml
The special thing, is that I use the org.codehaus.mojo buildnumber-maven-plugin and also the org.codehaus.mojo templating-maven-plugin.
I think it fails because of this, but I am unable to find how to fix it.
Here is the gitaction
https://github.com/a-schild/jave2/blob/master/.github/workflows/maven.yml
And here the error log of the build
[INFO] Executing: /bin/sh -c cd '/home/runner/work/jave2/jave2/jave-core' && 'git' 'log' '-n1' '--date-order'
[INFO] Working directory: /home/runner/work/jave2/jave2/jave-core
[INFO] Executing: /bin/sh -c cd '/home/runner/work/jave2/jave2/jave-core' && 'git' 'pull' 'https://github.com/a-schild/jave2.git'
[INFO] Working directory: /home/runner/work/jave2/jave2/jave-core
Error: Provider message:
Error: The git-pull command failed.
Error: Command output:
Error: From https://github.com/a-schild/jave2
* branch HEAD -> FETCH_HEAD
hint: You have divergent branches and need to specify how to reconcile them.
hint: You can do so by running one of the following commands sometime before
hint: your next pull:
hint:
hint: git config pull.rebase false # merge
hint: git config pull.rebase true # rebase
hint: git config pull.ff only # fast-forward only
hint:
hint: You can replace "git config" with "git config --global" to set a default
hint: preference for all repositories. You can also pass --rebase, --no-rebase,
hint: or --ff-only on the command line to override the configured default per
hint: invocation.
fatal: Need to specify how to reconcile divergent branches.
I have been trying to get more into the methodology of continuous integration as of recent, and have chosen Travis CI for the job. However, on one of my projects that uses Java and Kotlin my local builds pass, but fail on Travis.
I've been unable to make sense of the error messages that I am getting as to why my build is failing. kotlin-maven-plugin seems to be the origin of the errors. The problematic command as seen in the build logs is mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V.
I have run this command locally with no errors and a successful build.
Here's a relevant snippet of the stack trace from the CI Build Job:
[INFO] --- kotlin-maven-plugin:1.4.32:compile (compile) # BytesToJava ---
[ERROR] java.lang.ExceptionInInitializerError
at com.intellij.pom.java.LanguageLevel.<clinit>(LanguageLevel.java:25)
at com.intellij.core.CoreLanguageLevelProjectExtension.<init>(CoreLanguageLevelProjectExtension.java:26)
at com.intellij.core.JavaCoreProjectEnvironment.<init>(JavaCoreProjectEnvironment.java:42)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreProjectEnvironment.<init>(KotlinCoreProjectEnvironment.kt:26)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$ProjectEnvironment.<init>(KotlinCoreEnvironment.kt:121)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.createForProduction(KotlinCoreEnvironment.kt:425)
Would appreciate some resources or even a relevant issue thread. Thanks in advance :)
Travis Build Logs
The problem was being caused by an issue with illegal reflective operations and the Kotlin Maven Plugin with any project over Java 9 (my project uses Java 15). As described by this thread on YouTrack, a workaround is to:
A workaround is to run mvn with the following environment variable: MAVEN_OPTS=--illegal-access=permit
Adding a global environment variable with the same value to my .travis.yml fixed the issue.
I configured bitbucket-pipelines.yml and used image: gradle:6.3.0-jdk11. My project built on Java11 and Gradle 6.3. Everything was Ok till starting test cases. Because I used Testontainers to test the application. Bitbucket could not start up the Testcontainer.
The error is:
org.testcontainers.containers.ContainerLaunchException: Container startup failed
How can be fixed the issue?
If used Testcontainers inside the Bitbucket pipelines, There might be some issues. For instance, some issues like mentioned above. This issue can be fixed putting by following commands into bitbucket-pipelines.yml
Here the basic command is an environment variable.
TESTCONTAINERS_RYUK_DISABLED=true.
The full pipeline might be like this:
pipelines:
default:
- step:
script:
- export TESTCONTAINERS_RYUK_DISABLED=true
- mvn clean install
services:
- docker
definitions:
services:
docker:
memory: 2048
I have java project and I want to integrate it with SonarCloud I Follow the official steps:
Inspecting code with the SonarQube Scanner #
Before inspecting your code, you need to:
Create a user authentication token for your account on SonarCloud.
Encrypt this token travis encrypt abcdef0123456789 or define SONAR_TOKEN in your Repository Settings
Find which SonarCloud.io organization you want to push your project on and get its key
Create a sonar-project.properties file for your project (see the documentation). Then add the following lines to your .travis.yml file
to trigger the analysis:
add in my travis.yml file
addons:
sonarcloud:
organization: "xelian-github"
token:
secure: ${SONAR_TOKEN}
branches:
- master
script:
# other script steps might be done before running the actual analysis
- sonar-scanner
Where SONAR_TOKEN is a variable on Travis CI pointing to the key from SonarCloud.(It is not encrypted).
From SonarCloud I add permissions
But when I start the travis build I have the following error:
Setting environment variables from repository settings
$ export SONAR_TOKEN=[secure]
....
ERROR: Error during SonarQube Scanner execution
ERROR: You're only authorized to execute a local (preview) SonarQube analysis without pushing the results to the SonarQube server. Please contact your SonarQube administrator.
ERROR:
ERROR: Re-run SonarQube Scanner using the -X switch to enable full debug logging.
It seems to me that I the travis do not have permissions to upload results to SonarCloud. Is the problem in the token or in some Sonar configurations.
The official entry point to configure a project on SonarCloud is the "Get Started" page:
You will see that for Maven projects, you don't need to create a sonar-project.properties file at all
You will even find a link to a sample Maven project that is analyzed on SonarCloud
Finally I find a solution. In the root path whete the yml file is you have to add:
sonar-project.properties
# Required metadata
sonar.projectKey=java-sonar-runner-simple:master
sonar.projectName=Rss-service
sonar.projectVersion=1.0
# Comma-separated paths to directories with sources (required)
sonar.sources=/microservice-application/rss-reader-service/src/main/java
sonar.java.binaries=/microservice-application/rss-reader-service/target/classes
# Language
sonar.language=java
# Encoding of the source files
sonar.sourceEncoding=UTF-8
And in the travis.yml I add:
script:
# other script steps might be done before running the actual analysis
- mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install sonar:sonar
Edit:
sonar-project.properties not necessary. Only maven goals make sense.
Im trying to upload my project to circleci but from some reason it fails in a dropdown called "$ play test", I have no idea what is it, and I dont have tests in my project at all.
this is the section im talking about:
and im getting error there, this is the error:
I deleted "- sbt test" from my circle.yml so its not that, and I saw another folder of test in play so I thought maybe its that, but its empty, so I created a file in it and put nothing in it and still getting the same error...its driving me crazy ://///
please helpppppp
if you need this is my circle.yml:
machine:
services:
- docker
java:
version: oraclejdk8
environment:
SBT_VERSION: 0.13.9
SBT_OPTS: "-Xms512M -Xmx1536M -Xss1M -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=256M"
dependencies:
cache_directories:
- "~/.sbt"
- "~/.ivy2"
- "~/.m2"
- "~/docker"
pre:
- wget --output-document=$HOME/bin/sbt-launch.jar https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/sbt-launch/"$SBT_VERSION"/sbt-launch.jar
- echo "java $SBT_OPTS -jar \`dirname \$0\`/sbt-launch.jar \"\$#\"" > $HOME/bin/sbt
- chmod u+x $HOME/bin/sbt
- sbt sbt-version
override:
- sbt clean update
post:
- find . -type f -regex ".*/target/test-reports/.*xml" -exec cp {} $CIRCLE_TEST_REPORTS/ \;
general:
artifacts:
- "target/universal/*.tgz"
deployment:
feature:
branch: /.*/
commands:
- docker login -e admin#something.com -u ${ART_USER} -p ${ART_KEY} docker-local.artifactoryonline.com
- sbt -DBUILD_NUMBER="${CIRCLE_BUILD_NUM}" docker:publish
CircleCI has a feature called Inference that looks at what language your project is in as well as directories found, file extensions, etc to guess what dependencies and test you have.
If you look to the right of where you saw "play test" you'll see that it says "inference" which means this test was a result of Interference and not circle.yml. Inference made an assumption you needed the Play test framework (https://www.playframework.com/) and thus ran a default check, play test (the $ is part of the prompt).
If this is not what you want, which looks to be the case, you'll need to override the test command to instead run whatever test you want. This would be something like:
test:
override:
- echo "This is my test"
- ./my-custom-command
More information: https://circleci.com/docs/configuration/#test