powershell - "PowerShell on Target Machines"任务因 TFS 2017\Azure Dev Ops 中的错误而失败

标签 powershell azure-devops azure-pipelines azure-pipelines-build-task

我正在尝试使用我的 TFS 构建定义中的“PowerShell on Target Machines”任务运行存在于其中一台 Azure 服务器上的 PowerShell 脚本,但该任务失败并出现以下错误。

System.Management.Automation.RuntimeException: The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters. --->

我已经把脚本复制到F盘了,还是报路径太长的错误,找不到解决方法。

有谁知道是什么原因吗?

Screenshot of PowerShell on Target machine task

添加了脚本代码以供引用,

GetLatestDebugOutput.ps1

$DebugBuildOutput = "F:\Drops\econNextGen\SecurityScan\19.0"
$Dest = "F:\Drops\econNextGen\SecurityScan\Debug Build Output"


Remove-Item "$Dest\*" -Recurse -Force

#Code to Copy Common-App Debug Build
$Dir= $DebugBuildOutput + "\econNextGen-Common-App-Debug\"
$Latest = Get-ChildItem -Path $Dir | Sort-Object LastAccessTime -Descending | Select-Object -First 1
$FolderPath= $Dir +$Latest.Name 
Copy-Item -Path $FolderPath $Dest –Recurse -force


#Code to Copy Main-App Debug Build
$Dir= $DebugBuildOutput + "\econNextGen-MAIN-APP-Debug\"
$Latest = Get-ChildItem -Path $Dir | Sort-Object LastAccessTime -Descending | Select-Object -First 1
$FolderPath= $Dir +$Latest.Name 
Copy-Item -Path $FolderPath $Dest –Recurse -force

最佳答案

首先建议您直接通过 RDP 连接到远程目标机器,并检查您是否能够在其中运行相同的脚本。如果问题与您的 tfs 构建定义和环境相关,这将缩小范围。

对于环境,请确保您已满足此 PowerShell on Target Machines task 的所有先决条件 .并且您已经安装了合格的 powershell 版本。

实际上,错误消息非常简单明了,您应该注意的关键点也是如此:确保您没有使用太长的路径或使用无效的路径。如果申请所有文件夹和文件。

此外,尝试启动 build with diagnostics\debug enabled使用 system.debug=true 并查看是否可以获得任何有意义的输出以用于将来的故障排除。

关于powershell - "PowerShell on Target Machines"任务因 TFS 2017\Azure Dev Ops 中的错误而失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58821034/

相关文章:

powershell - 最大化窗口并使用Powershell将其置于最前面

php - 如何使用 PHP 验证 Azure 广告 b2c token ?

使用 64BitCompiler 时 UWP 构建失败

azure-devops - 发布中的 VSTS 程序集版本

sql-server - 为 Dacpac 和 Powershell 脚本创建 Nuget 包

regex - Powershell + 正则表达式 - 如何获得多个匹配项?

powershell - 使用PowerShell命令行时未捕获到异常,但使用PowerShell ISE时却按预期捕获了异常

azure - Azure DevOps 管道作业在什么服务主体下运行?

.net-core - 在 Azure Pipelines 构建中命名生成的 ZIP 存档?

azure - 如何使用 Azure DevOps Pipeline 打开/关闭 Azure 应用服务的 "Https only"?