我正在嘗試使用PowerShell任務開啟inline模式計算 Azure Pipeline 中某個任務所用的時間。簡化的設定看起來像所附的影像。行內代碼如下所述。我得到低于指定的錯誤。
Calculating Elapsed Time...
Cannot find an overload for "op_Subtraction" and the argument count: "2".
At D:\a\_temp\ba6b91f4-ef47-4a51-8088-efc6bcda310d.ps1:5 char:1
$duration_min = $end_time - $start_time
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CategoryInfo : NotSpecified: (:) [], ParentContainsErrorRecordException
FullyQualifiedErrorId : MethodCountCouldNotFindBest
##[error]PowerShell exited with code '1'.
測量構建任務所用時間的正確方法是什么?
管道設定:

Get Start Time行內 powershell 任務中的代碼:
$start_time = Get-Date
Write-Host "Scanning Start Timestamp: $($start_time)"
Calculate Elapsed Time行內 powershell 任務中的代碼:
Write-Host "Calculating Elapsed Time..."
$end_time = Get-Date
$duration_min = $end_time - $start_time
Write-Host ("Total Time Elapsed in Minutes: ", $duration_min.TotalMinutes)
uj5u.com熱心網友回復:
任務之間的變數是獨立的。為了在任務之間傳遞值,我們可以使用管道變數。在您的設定中,轉到變數選項卡并創建一個新變數 - 比如說 scan_start_time。
在“獲取開始時間”任務中添加另一行
Write-Output "##vso[task.setvariable variable=scan_start_time]$($start_time)"
然后在“計算經過時間”任務中
$start_time = "$(scan_start_time)"
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/395665.html
標籤:电源外壳 azure-devops 天蓝色管道 天蓝色管道构建任务 天蓝色管道任务
