Phpunit and Junit parsing - correct usage

Hi All

I currently have a test stage and i execute the following in my docker image that gets spun up for testing.

                echo 'Running PHPUnit tests...'
                sh './vendor/bin/phpunit --coverage-html ./report/clover --coverage-clover ./report/clover.xml --log-junit ./report/junit.xml'
                echo 'JUnit parsing of data...'
//                 sh 'chmod -R a+w $PWD && chmod -R a+w .'
//                 junit './report/*.xml'

My Php unit tests have 2 failures but i want to somehow get this back to the developer. After the tests fail it doesnt get to the “echo ‘JUnit parsing of data…’”.

What is the correct flow to get the report back to dev’s? Slack attachment or links? and how?


I’d avoid the word correct. Correct implies there’s only one way to do it.

My personal suggestion is to add a post step and pass it into the junit plugin

You could wrap the sh in a captureError which I think would work for this case. Build would fail, but you can still do stuff in this stage.

as for how to notify, slack plugin works pretty good, some people use email. I’ve tried discord. There’s teams and jira plugins. Lots of options.

1 Like

Thank you @halkeye

                catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
                    sh '''
                     ./vendor/bin/phpunit \
                     --coverage-html ./report/clover \
                     --coverage-clover ./report/clover.xml \
                     --testdox-html ./report/testdox.html
                echo 'Sending failure report...'
                slackUploadFile channel: "digital-dealership-logs", filePath: 'report/testdox.html', initialComment: 'Test report'

The above worked and i get the report in slack but what i think im going to do is follow this step on building a html report in jenkins itself and then slack the link to the html report.

Ill do this so everything is contained within jenkins for history.


I recommend junit and warnings-ng integrations as well, gives you lots of useful data and details

@halkeye Ive seen JUnit. To be honest, im not sure how to use it and what it does exactly.

I read Java usage and then i stopped reading…

not the best habit to be in. Junit is a semi standard these days (although poorly defined one), essentially lots of tools output to a junit.xml like format, then the junit plugin can process it, and build reports for you.

Example: demos/halkeye-newman #1 NewmanTest [Jenkins] (built to demo another thread)

1 Like


So after my catch which i have in place i just call junit with the xml and a report gets attached to my pipeline process automatically?

junit './report/*.xml'