“PowerShell on Target Machines” task fails with an error in TFS 2017\Azure Dev Ops

允我心安 提交于 2019-12-24 00:47:32

问题


I am trying to run a PowerShell script present on one of the azure server using the "PowerShell on Target Machines" Task in my TFS build definition, but the task fails with the below error.

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. --->

I have copied the script in F drive but it still gives path too long error, not able to find any solution for the same.

Does anyone know what would be the reason?

Added script code as well for reference,

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

回答1:


First suggest you directly RDP to remote target machine and check if you are able to run the same script in it. This will narrow down if the issue related to your tfs build definition and environment.

For environment, make sure you have met all prerequisites of this PowerShell on Target Machines task. And you have qualified powershell version installed.

Actually the error message is pretty straight forward, and so is the key point you should pay attention to: make sure you're not using paths that are too long or using an invalidly path. If apply for all folder and files.

Besides, try starting the build with diagnostics\debug enabled with system.debug=true and see if you can get any meaningful output for future troubleshooting.



来源:https://stackoverflow.com/questions/58821034/powershell-on-target-machines-task-fails-with-an-error-in-tfs-2017-azure-dev-o

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!