'Adding HTML report that change dynamically to mail after build in Jenkins
I already built a stage that sends mail in the end of the build with the status of it and it works perfect. I want to add to this mail an html report of tests that ren in the build. the problem is that the name of the .html file includes the date and time that it was created after every build. This is my mail sending script
post{
always{
echo '------------------------------- SENDING INFORMATIVE MAIL -------------------------------'
emailext subject: "[Jenkins] ${currentBuild.displayName} : ${currentBuild.currentResult}",
body: '''${SCRIPT, template="groovy-html.template"}''', mimeType: 'text/html', attachLog: true,
to: """${RECIPIENTS}"""}
}
this it the file name of the last test:
ADU_TEST_REPORT_02_03_2022_09_31.html
the part the changes every build is this: _02_03_2022_09_31
it is in the path: C:\Jenkins\workspace\Deprtment\Builds\DevOps Builds\Checks\Test_Reports
I tried to add this
(${FILE,path="C:\Jenkins\workspace\Deprtment\Builds\DevOps Builds\Checks\Test_Reports\ADU_TEST_REPORT*.html"})
to the script but it didn't work. What do I do wrong? and do anybody knows how to do it the right way?
------------------------------------ U P D A T E-------------------------------------------
I wrote a python script that writes the name of the most updated file name (with correct date and time) to a .txt file and then i read that txt with groovy in the pipeline. but when i add this string to the file path it sends me an email with the error:
ERROR: File 'C:JenkinsworkspaceDeprtmentBuildsDevOps BuildsChecksTest_Reports${testReportName}' does not exist
What am i doing wrong? this is my code:
post{
always{
script{
echo '------------------------------- RUN PYTHON SCRIPT THAT FINDS TEST REPORT NAME -------------------------------'
bat """${python_27} "C:\\Users\\dp1234\\Desktop\\TestReportName.py" """
echo '------------------------------- PYTHON SCRIPT EXECUTED - TEST REPORT NAME SAVED IN .txt -------------------------------'
echo '------------------------------- RECEIVE TEST REPORT NAME -------------------------------'
def testReportName = readFile "C:\\Users\\dp1234\\Desktop\\testReports.txt"
echo """${testReportName}"""
echo '------------------------------- TEST REPORT NAME SAVED -------------------------------'
echo '------------------------------- SENDING INFORMATIVE MAIL -------------------------------'
emailext subject: "[Jenkins] ${currentBuild.displayName} : ${currentBuild.currentResult}",
body: '''${SCRIPT, template="groovy-html.template"}''', mimeType: 'text/html', attachLog: true,
//body: '''${FILE, path="C:\\Jenkins\\workspace\\Deprtment\\Builds\\DevOps Builds\\Checks\\Test_Reports\\${testReportName}"}''', mimeType: 'text/html', attachLog: true,
to: """${RECIPIENTS}"""}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
