I have pipeline in Azure DevOps, in which Gatling loading test scenario executes every night. How can I get notification in Azure (and on e-mail also) in case total runtime in last time is more than in previous time (e.g. 31.03.2020 total runtime was 10 min, 01.04.2020 total runtime was 12 min - in this case i want to get notification)?
You can create a new build pipeline which only is triggered by the Build Completion of your test pipeline.
And add a script task to call Build rest api to this new pipeline to calculate the total runtime of the builds. And add a Send email task to send you email on the condition of duration time is greater than the previous build. The detailed steps is listed as below.
1, Setup a new pipeline and configure the Build Completion trigger
Go to Get sources --> Check Don't sync sources to skip checkout sources
Click Agent job--> Check Allow scripts to access the OAuth token to allow scripts to call rest api
Go to Triggers tab--> Build completion--> Click Add to select your test pipeline as Trigggering build
By setting up the Build completion Triggering build, this new pipeline will be triggered when your test pipeline is complete.
2, Add a script task to call Build rest api and calculate the duration time. And store the result to a variable. Check below powershell script:
$url = "$(System.TeamFoundationCollectionUri)$(System.TeamProject)/_apis/build/builds/$(Build.TriggeredBy.BuildId)?api-version=5.1"
echo $url
$result = Invoke-RestMethod -Uri $url -Headers @{authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"} -ContentType "application/json" -Method get
# calculate the totaltime of the newest build
$time = [datetime]$result.finishTime - [datetime]$result.startTime
$thisBuild= $time.TotalMinutes
# get the last build
$lasturl = "$(System.TeamFoundationCollectionUri)$(System.TeamProject)/_apis/build/builds?definitions=$(Build.TriggeredBy.DefinitionId)&resultFilter=succeeded&`$top=2&api-version=5.1"
$lastResult =Invoke-RestMethod -Uri $lasturl -Headers @{authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"} -ContentType "application/json" -Method get
#Caculate the totaltime of the last build
$lasttime = [datetime]$lastResult.value[1].finishTime - [datetime]$lastResult.value[1].startTime
$lastBuild = $lasttime.TotalMinutes
#Store the result to varialbe isLonger
if($thisBuild -ge $lastBuild ){ echo "##vso[task.setvariable variable=isLonger]True" }
3, Add Send email task to send out the email. And set a custom condtion to eq(variables.isLonger, 'True')
. So that this task will only be executed when the total time is greater.
Hope above helps!