Skip to content

ANSI codes produce JUnit-format XML rejected by Jenkins #846

@jglick

Description

@jglick

Describe the bug
ANSI display sequences emitted by tests are displayed fine in regular output in a terminal (--show-output-of-passing-tests). But if you use --report-formatter junit, output includes , which is forbidden in XML 1.0 as far as I know. In particular, the Jenkins junit step does not accept it, preventing the entire test suite from being reported.

To Reproduce

Run e.g.

kind create cluster
kubectl cluster-info

in a test suite. Record JUnit-format output and use https://plugins.jenkins.io/junit/ to display the test report. It will fail:

Failed to read test report file …/report.xml
org.dom4j.DocumentException: Error on line 1234 of document  : Character reference "&#27" is an invalid XML character.
	at org.dom4j.io.SAXReader.read(SAXReader.java:511)
	at org.dom4j.io.SAXReader.read(SAXReader.java:392)
	at hudson.tasks.junit.SuiteResult.parse(SuiteResult.java:186)

In the XML you can see something like

<?xml version="1.0" encoding="UTF-8"?>
<!---->
<system-out>$$$ [x.bats, line 123]
<!---->
&#27;[0;32mKubernetes control plane&#27;[0m is running at &#27;[0;33mhttps://127.0.0.1:39377&#27;[0m
&#27;[0;32mCoreDNS&#27;[0m is running at &#27;[0;33mhttps://127.0.0.1:39377/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy&#27;[0m
<!---->

Expected behavior
Either control characters are omitted from the XML, or U+001B is represented as e.g. ^[, or (ideally) the entire ANSI code is stripped to produce plain text:

Kubernetes control plane is running at https://127.0.0.1:39377
CoreDNS is running at https://127.0.0.1:39377/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

Environment (please complete the following information):

  • Bats version 1.10.0
  • operating system (including version): Ubuntu 22.04.3
  • bash --version: 5.1.16
  • Install method: clone & install.sh

Additional context
See #311 & #345.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Component: Bash CodeEverything regarding the bash codePriority: HighBroken behavior in specific environments like in parallel mode or only on some operating systemsSize: MediumChanges in the same fileType: Bug

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions