1

I'm trying to parse the output from a BATS script (https://github.com/gaia-adm/docker-bench-test) which outputs into TAP format. I've modified the scripts slightly to cover CIS 1.13 instead of 1.11, but I don't know how to make Jenkins Pipeline handle that output.

I know there is a Jenkins plugin for TAP format, but I don't believe this works with Jenkins Pipeline Groovy scripts.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Steve Button
  • 111
  • 1
  • 9

2 Answers2

1

@Grab will work only if you jenkins has access to the internet

workspace/job_name/tap.groovy

@Grab(group='org.tap4j', module='tap4j', version='4.2.1')

import org.tap4j.consumer.TapConsumerFactory

def parse(def src){
    return TapConsumerFactory.makeTap13Consumer().load(src)
}

return this

workspace/job_name/test.tap

1..3
ok 1 - no error
not ok 2 - io error
ok 3 - no error

Pipeline script

node{
    def tap = load 'tap.groovy'
    tap = tap.parse( readFile('test.tap') )
    echo  "Number of tests found : ${tap.getNumberOfTestResults()}"
    echo  "Test Set failed?      : ${tap.containsNotOk()}"
}

Output

Number of tests found : 3
Test Set failed?      : true

The object returned by tap.parse(): org.tap4j.model.TestSet

daggett
  • 26,404
  • 3
  • 40
  • 56
0

With the tap plugin installed I was able to get my declarative pipeline script to display test results from tap files with the following command:

stage('publish test results') {
    steps {
        step([$class: "TapPublisher", testResults: "**/reports/*.tap"])
    }
}

How do i use the "Publish TAP Results" plugin on Jenkins 2.0 Pipeline?

kongkoro
  • 792
  • 3
  • 7