Integrating TestPulse in Drone

In this section we will modify a Drone CI pipeline and add a new step that uploads test results to TestPulse.

For simplicity we will use a Java pipeline, but the upload step is not different for other languages!

Our initial pipeline configuration looks like this:

kind: pipeline
type: docker
name: amazing-pipeline

steps:
- name: Build and run unit tests
  image: amazoncorretto:21-alpine-jdk
  commands:
  - ./gradlew clean test

trigger:
  branch:
  - main
  event:
  - push
  - pull_request

As you can see, we simply use the amazoncorretto Docker image for Java, and then run ./gradlew clean test.

When Gradle runs, it will create test reports. We now need to upload these reports to TestPulse to analyze.

Add TESTPULSE_TOKEN as a secret

The token you created after installing the app is used for authenticating your user (CI pipeline) when uploading test results to us. If not passed correctly, the upload will fail.

We need to add this token in Drone CI. You can find more information on how add a secret on their website.

If we need to add the secret in a repository, simply navigate to the repository settings screen:

The name can be anything, the value MUST be the token we showed you in the previous step.

Add TestPulse upload step

Now that everything is in place, we can modify our pipeline and add a new step that uploads the test results and coverage to TestPulse.

Since our utility is written in python, the step will use the python Docker image. Then, install our python utility called testpulse-uploader using pip install.

Finally, call testpulse-upload and pass all the necessary parameters. The full list of parameters is explained in its documentation.

An environment variable named TESTPULSE_TOKEN should be assigned to the token that’s stored as a secret.

For example:

kind: pipeline
type: docker
name: amazing-pipeline

steps:
- name: Build and run unit tests
  image: amazoncorretto:21-alpine-jdk
  commands:
  - ./gradlew clean test
- name: Upload to TestPulse
  image: python:3.12
  environment:
    TESTPULSE_TOKEN:
      from_secret: TESTPULSE_TOKEN      # this should match the name of your secret!
  commands:
  - pip install testpulse-uploader
  - testpulse-upload -tr "build/test-results/test/.*\.xml" -cr "build/reports/jacoco/test/.*\.xml" --config-file .testpulse.yaml
  when:
    status:
    - success
    - failure

trigger:
  branch:
  - main
  event:
  - push
  - pull_request

The uploader has many options. We suggest you to read its its documentation.

Worth mentioning:

  • make sure you modify the path to the test results and coverage files!
  • the when: clause specifies when the step should run. It’s important that we upload test results even if there are failures!
  • TESTPULSE_TOKEN: make sure to set this env variable, or you will get an authentication error

Push some code and check the results

Configuration-wise, you are done! The next time you run this job, the test results will be imported in TestPulse.