复制项目:该过程无法访问文件电源



我在尝试从路径到目标复制项目时,请看到以下错误日志。此PS脚本任务安排在Jenkins作业下。每次构建失败时,这都会弄乱事物。

错误日志 -

Copy-Item : The process cannot access the file 
'\10.0.1.190d$BuildRPCFortius.RPC.AmadeusAirCommon.Logging.Core.dll' because it is being used by another process.
At C:UsersAdministratorAppDataLocalTemphudson5254771699639808940.ps1:33 char:1
+ Copy-Item "$ReleaseDir*" $AmadeusDir -Force -Recurse
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Copy-Item], IOException
    + FullyQualifiedErrorId : System.IO.IOException,Microsoft.PowerShell.Commands.CopyItemCommand

ps脚本 -

# force strict - so any variable used before being assigned causes an error
Set-PsDebug -Strict
# force PowerShell to exit with a non-zero code on the first error
$ErrorActionPreference = 'Stop'
# set directories here once, so we can reuse
$AmadeusDir = "\$env:SERVERd$BuildRPCFortius.RPC.AmadeusAir"
$ReleaseDir   = "C:AmadeusBTPsrcFortius.Amadeus.Air.RPC.HostbinRelease"
# get directory contents (are you expecting these to return to Jenkins?)
Get-ChildItem "$AmadeusDir*"
Get-ChildItem "$ReleaseDir*" 
# create the search directory if it doesn't exist
if (-not (Test-Path -Path $AmadeusDir -PathType Container)) { New-Item -Path $AmadeusDir -type directory -Force }
# get the service, but fail gracefully if it doesn't exist
$service = Get-Service -Name AmadeusAirWindowsService -Computername $env:SERVER -ErrorAction SilentlyContinue
# if we have a service, stop and delete it
if($service.Status)
{
    sc.exe \$env:SERVER stop AmadeusAirWindowsService
    if ($LASTEXITCODE -ne 0) { throw "error stopping the service: $LASTEXITCODE" }
    Write-Host "AmadeusAirWindowsService STOPPED"
    sc.exe \$env:SERVER delete AmadeusAirWindowsService
    if ($LASTEXITCODE -ne 0) { throw "error deleting the service: $LASTEXITCODE" }
    Write-Host "AmadeusAirWindowsService DELETED"
}
# copy release to search
Copy-Item "$ReleaseDir*" $AmadeusDir -Force -Recurse
# (re)create the service
sc.exe \$env:SERVER create AmadeusAirWindowsService start=auto DisplayName="Fortius Amadeus Air RPC Service"  binPath= D:BuildRPCFortius.RPC.AmadeusAirWorldVentures.Fortius.Amadeus.Air.RPC.Host.exe
if ($LASTEXITCODE -ne 0) { throw "error creating the service: $LASTEXITCODE" }
sc.exe \$env:SERVER description AmadeusAirWindowsService "This service hosts Fortius Amadeus Air RPC service"
if ($LASTEXITCODE -ne 0) { throw "error adding description to service: $LASTEXITCODE" }
sc.exe \$env:SERVER start AmadeusAirWindowsService
if ($LASTEXITCODE -ne 0) { throw "error starting the service: $LASTEXITCODE" }
Write-Host "AmadeusAirWindowsService STARTED"

作为替代者,我正在使用 xcopy "From" "destination" /k/e/d/Y

您正在尝试在目标仍然使用文件时复制东西。您是否检查过将此文件锁定的是什么?您已经停止了我看到的服务,您是否真的检查了是否成功?同样,Sysinternals具有"句柄"one_answers" Process Explorer",它们既可以检查要锁定文件的内容。

最新更新