How to attach multiple html reports as email body through JENKINS

612 views Asked by At

I have used below lines to attach single report as email body and it works as expected through jenkins.

   def report=build.getWorkspace().child("target/reports/report.html")
   msg.setContent(report.readToString(),"text/html")

There are many files in the reports directory which starts with report1.html, report2.html etc., I just want to fetch all and show it as email content as I did before.

The html reports are dynamically generated,and there is a only way to identify that the html starts with "report".

Anyone ideas....

1

There are 1 answers

1
chenchuk On

I didnt try but since readToString() returns a string, its maybe possible to concatenate all reports to a single string, and then pass it to the setContent() method:

#!groovy
def report1=build.getWorkspace().child("target/reports/report1.html")
def report2=build.getWorkspace().child("target/reports/report2.html")

def all_reports = report1.readToString() + "\n" + report2.readToString()
msg.setContent(all_reports,"text/html")