Under $JENKINS_HOME/jobs/GSP/workspace/build/work/plugins(we call this folder as "basedir"), there are many bundle folders. Some of them were compiled, so there are many test report file "TEST-
<?xml version="1.0" encoding="UTF-8" ?>
...
In this case the testcase number is 3 according to 'test="3"'. Now we need get the total number of testcases with following steps:
-
find all these test report file under ${basedir};
-
get the testcase number;
-
add all these number up;
-
print the result;
We achieve this by the following command under ${basedir}:
grep -Po '(?<=tests=")\d+' */TEST-.xml | awk -F':' '{SUM += $2; print $1 ": " $2} END {print "Total: " SUM}'
"-P" let grep interpret pattern as perl regular expression. "-o" means only output the matched part. "(?>=...)" eliminates the text in parenthesis. "-F" of awk specify the delimiter. This command works on zsh because the "*/" syntax only valid on zsh. If you use bash, you have to modify this.