Skip to content

Commit 158de7f

Browse files
committed
Add to upload_ciapp.sh
1 parent a3e9bda commit 158de7f

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

.circleci/upload_ciapp.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@ java_prop() {
1717
echo "$JAVA_PROPS" | grep "$PROP_NAME" | head -n1 | cut -d'=' -f2 | xargs
1818
}
1919

20+
# Add the 'file' attribute to the JUnit XML file
21+
add_source_file_to_xml() {
22+
local XML_FILE=$1
23+
local ESCAPED_FILE
24+
25+
# Escape special characters in the filename (such as /, &, etc.)
26+
ESCAPED_FILE=$(printf '%s' "$XML_FILE" | sed 's/[&/\]/\\&/g')
27+
28+
# Insert the 'file=ESCAPED_FILE' attribute in each <testcase>
29+
sed -i '' "/<testcase/ s/\(<testcase[^>]*\)\(\/\)/\1 file=\"$ESCAPED_FILE\"\2/" "$XML_FILE"
30+
}
31+
2032
# Upload test results to CI Visibility
2133
junit_upload() {
2234
# based on tracer implementation: https://github.com/DataDog/dd-trace-java/blob/master/dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/instrumentation/decorator/TestDecorator.java#L55-L77
@@ -36,6 +48,11 @@ junit_upload() {
3648
# Make sure we do not use DATADOG_API_KEY from the environment
3749
unset DATADOG_API_KEY
3850

51+
# Modify the JUnit XML results by adding the 'file' attribute
52+
for XML_FILE in ./results/*.xml; do
53+
add_source_file_to_xml "$XML_FILE"
54+
done
55+
3956
# Upload test results to production environment like all other CI jobs
4057
junit_upload "$DATADOG_API_KEY_PROD"
4158
# And also upload to staging environment to benefit from the new features not yet released

0 commit comments

Comments
 (0)