如何在“ Invoke Rest API”中获得管道起点和终点时间?

时间:2019-09-09 21:35:02

标签: azure-devops

我在管道中最后一个作业的“部署后条件”下添加了一个“调用Rest API”任务。我将需要将管道的开始和结束时间发布到其他API。获得这两个值的变量是什么?

为Rest API Post操作生成的默认标头。

{
"Content-Type":"application/json", 
"PlanUrl": "$(system.CollectionUri)", 
"ProjectId": "$(system.TeamProjectId)", 
"HubName": "$(system.HostType)", 
"PlanId": "$(system.PlanId)", 
"JobId": "$(system.JobId)", 
"TimelineId": "$(system.TimelineId)", 
"TaskInstanceId": "$(system.TaskInstanceId)", 
"AuthToken": "$(system.AccessToken)"
}

需要获取管道StartTimeEndTime以及Status

1 个答案:

答案 0 :(得分:1)

我在powershell任务中对其进行了测试,并通过以下脚本获得了状态和startTime。

$url = "https://vsrm.dev.azure.com/{org}/{project}/_apis/release/releases/$(Release.releaseId)?api-version=5.1"
$pipeline = Invoke-RestMethod -Uri $url -Headers @{   
 Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"
} -Method Get

$test0 = $pipeline.environments.deploySteps.releaseDeployPhases.deploymentJobs.job.status

Write-Host $test0

$test1 = $pipeline.environments.deploySteps.releaseDeployPhases.deploymentJobs.job.startTime

Write-Host $test1

enter image description here