0

I am running a tomcat server and in it's catalina.sh I have exported JAVA_OPTS as follows.

JAVA_OPTS="$JAVA_OPTS -javaagent:/opt/jacoco/lib/jacocoagent.jar=destfile=/tmp/jacoco.exec,append=true,includes=*"

This generates the jacoco.exec file in the same machine in /tmp folder. How do I generate the exec file on a remote machine for instance a machine that is a jenkins slave so that I can get the coverage via sonar.

station
  • 6,715
  • 14
  • 55
  • 89

1 Answers1

0

To achieve this, you need to ensure multiple points:

  1. do you have the jacocoagent.jar available on your jenkins node in /opt/jacoco/lib?

    if not, you can

    • [Solution a] either put it there, then the basic configuration is correct,
    • [Solution b] check it in with your code, or load it via maven, etc. - so it is part of your "implmentation" - eg. we put it in our execution-root so we just have javaagent:jacocoagent.jar
  2. you need to adapt your log output destfile=/tmp/jacoco.exec

    As this is a absolute path, it will always generate the output there, and i am not sure if you can access it from there, within your jenkins job

    • [Solution A] you make the destfile relative like ./build/jacoco.exec, than you will find it within your workspace on jenkins
    • [Solution B] you just do not provide this field, than it will be named jacoco.exec and will be within the execution folder
  3. You need to provide the path to this file based on https://docs.sonarqube.org/display/PLUG/Usage+of+JaCoCo+with+Java+Plugin

i hope i could help :D

Simon Schrottner
  • 4,146
  • 1
  • 24
  • 36