[如果新版本的总运行时间更多,如何在Azure中获取通知

问题描述 投票:0回答:1

我在Azure DevOps中具有管道,在其中每晚执行一次加特林加载测试方案。如果上次的总运行时间大于以前的时间(例如31.03.2020的总运行时间为10分钟,01.04.2020的总运行时间为12分钟),我如何在Azure中(以及也在电子邮件上)获得通知如果我想得到通知)?

scala azure-devops azure-pipelines gatling
1个回答
0
投票
并添加脚本任务以调用Build rest api到此新管道,以计算构建的总运行时间。并添加一个Send email task以在持续时间大于先前构建的条件下发送给您。详细步骤如下。

1,设置新管道并配置构建完成触发器

转到

获取来源->选中

不同步来源以跳过结帐来源enter image description here

单击代理作业->选中

允许脚本访问OAuth令牌

,以允许脚本调用rest apienter image description here转到触发器选项卡->

构建完成

->单击添加将测试管道选择为触发器构建enter image description here2,添加脚本任务以调用Build rest api并计算持续时间。和store the result to a variable。检查下面的powershell脚本:

$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,添加发送电子邮件任务以发送电子邮件。并将自定义条件设置为eq(variables.isLonger, 'True')。因此只有在总时间更长时才执行此任务。

enter image description here

希望以上帮助!

© www.soinside.com 2019 - 2024. All rights reserved.