我已经创建了一个自定义任务来检查构建代码覆盖率的百分比,但是在运行时通过vNext(内部部署,而不是VSO)运行时出现错误。直接在构建服务器上运行相同的PowerShell脚本。
错误是由于一些没有值的变量造成的。但是,直接在服务器上运行时,这些相同的变量具有正确的值。
从下面的输出中,“1”回报不同,这可能是问题的根源。
在自定义任务中运行时,尝试通过PowerShell中的API查询TFS时是否有其他人发现了问题?
这是PowerShell负责“1. 2. 3. 4.”下面输出中的位......
[Reflection.Assembly]::Load("Microsoft.TeamFoundation.Client, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a") | Out-Null
[Reflection.Assembly]::Load("Microsoft.TeamFoundation.TestManagement.Client, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a") | Out-Null
[Reflection.Assembly]::Load("Microsoft.TeamFoundation.TestManagement.Common, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a") | Out-Null
[Reflection.Assembly]::Load("Microsoft.TeamFoundation.Build.Client,Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a") | Out-Null
[String] $CollectionUrl = "$env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI"
[String] $BuildUrl = "$env:BUILD_BUILDURI"
[String] $project = "$env:SYSTEM_TEAMPROJECT"
$tfs = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($CollectionUrl)
Write-Host "1. $tfs"
$service = $tfs.GetService([Microsoft.TeamFoundation.TestManagement.Client.TestManagementService])
Write-Host "2. $service"
$teamproject = $service.GetTeamProject($project)
Write-Host "3. $teamproject"
$totalRuns = $teamproject.TestRuns.ByBuild($BuildUrl)
Write-Host "4. $totalRuns"
这是我构建任务的输出......
2016-05-10T10:52:16.5856277Z Executing the powershell script: F:\BuildAgents\3\tasks\CheckCodeCoverage\0.1.0\CheckCodeCoverage.ps1
2016-05-10T10:52:16.7666452Z Desired Code Coverage Percent is 80
2016-05-10T10:52:17.4527107Z CollectionUrl = http://hvn******02:8080/tfs/**********/
2016-05-10T10:52:17.4537113Z BuildUrl = vstfs:///Build/Build/4708
2016-05-10T10:52:17.4547103Z project = HP
2016-05-10T10:52:17.4867134Z 1. http://hvn******02:8080/tfs/**********
2016-05-10T10:52:17.5017245Z 2.
2016-05-10T10:52:17.5497201Z ##[error]System.Management.Automation.RuntimeException: You cannot call a method on a null-valued expression.
2016-05-10T10:52:17.5507204Z ##[error] at CallSite.Target(Closure , CallSite , Object , String )
2016-05-10T10:52:17.5517213Z ##[error] at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
2016-05-10T10:52:17.5527209Z ##[error] at System.Management.Automation.Interpreter.DynamicInstruction`3.Run(InterpretedFrame frame)
2016-05-10T10:52:17.5527209Z ##[error] at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
2016-05-10T10:52:17.5537202Z 3.
2016-05-10T10:52:17.5587208Z ##[error]System.Management.Automation.RuntimeException: You cannot call a method on a null-valued expression.
2016-05-10T10:52:17.5597209Z ##[error] at CallSite.Target(Closure , CallSite , Object , String )
2016-05-10T10:52:17.5607212Z ##[error] at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
2016-05-10T10:52:17.5617229Z ##[error] at System.Management.Automation.Interpreter.DynamicInstruction`3.Run(InterpretedFrame frame)
2016-05-10T10:52:17.5617229Z ##[error] at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
2016-05-10T10:52:17.5627218Z 4.
2016-05-10T10:52:17.5897235Z 0 is the Code Coverage. Failing the build
这是直接在同一台服务器上运行的输出......
PS F:\BuildAgents\3\tasks\CheckCodeCoverage\0.1.0> .\CheckCodeCoverage.ps1 -requiredpercent 80
Desired Code Coverage Percent is 80
CollectionUrl = http://hvn******02:8080/tfs/**********/
BuildUrl = vstfs:///Build/Build/4708
project = HP
1. hvn******02\**********
2. Microsoft.TeamFoundation.TestManagement.Client.TestManagementService
3. HP
4. TestRun instance 26465375
BugsCount: 0
BuildConfigurationId: 4047
BuildFlavor: release
BuildNumber: 0.0.0.21
BuildPlatform: any cpu
BuildUri: vstfs:///Build/Build/4708
Comment:
CompleteDate: 10/05/2016 11:52:15
Controller:
CreationDate: 10/05/2016 11:52:16
DropLocation:
DueDate: 01/01/0001 00:00:00
ErrorMessage:
Id: 3563
IncompleteTests: 0
IsAutomated: True
IsBvt: False
Iteration: HP
LastUpdated: 10/05/2016 11:52:16
LastUpdatedBy: 7261134a-7631-49fa-b554-9d1fa6684d73
LastUpdatedByName:
LegacySharePath:
NotApplicableTests: 0
Owner: 7261134a-7631-49fa-b554-9d1fa6684d73
OwnerName:
PassedTests: 2
PostProcessState: 3
PublicTestSettingsId: 0
Revision: 5
ServiceVersion: 11.42.0
StartDate: 10/05/2016 11:52:15
State: 3
TeamProject: HP
TestEnvironmentId: 00000000-0000-0000-0000-000000000000
TestMessageLogId: 0
TestPlanId: 0
TestRunStatistics: [0]
TestSettingsId: 0
Title: VSTest Test Run release any cpu
TotalTests: 2
Type: 4
UnanalyzedTests: 0
Version: 0
Code Coverage percentage is 100
CodeCoverage limit met
PS F:\BuildAgents\3\tasks\CheckCodeCoverage\0.1.0>