Reputation: 520
I have a task that generate HTML reports, for example:
Api-Test-Automation-2019-06-23-12-35-54-450-0.html
Api-Test-Automation-2019-06-23-12-38-44-701-0.html
I want to get the latest report and send it in the email as attachment.
This will actually attach all files:
$(Build.SourcesDirectory)\newman\htmlreport\*.html
But I just want to add only the latest created file.
Upvotes: 0
Views: 688
Reputation: 41735
So you have 2 HTML reports and you want to send only the last report. you can achieve this goal with a PowerShell task that set a variable with the last file path (add a PowerShell task after the html generation):
cd $(Build.SourcesDirectory)\newman\htmlreports
$files = dir -Filter *.html
$latest = $files | Sort-Object LastAccessTime -Descending | Select-Object -First 1
$lastFile = $latest.FullName
Write-Host "##vso[task.setvariable variable=latestHtml]$lastFile"
Now in the send email task just put the variable $(latestHtml)
.
Upvotes: 2