2017-02-20 51 views
0

我在下面看到錯誤日誌,當我嘗試將項目從路徑複製到目標。此PS腳本任務安排在Jenkins Job下。由於每次構建都失敗,這會讓事情變得糟糕。複製項目:進程無法訪問該文件Power-Shell

錯誤日誌 -

Copy-Item : The process cannot access the file 
'\\10.0.1.190\d$\Build\RPC\Fortius.RPC.AmadeusAir\Common.Logging.Core.dll' because it is being used by another process. 
At C:\Users\Administrator\AppData\Local\Temp\hudson5254771699639808940.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:SERVER\d$\Build\RPC\Fortius.RPC.AmadeusAir" 
$ReleaseDir = "C:\Amadeus\BTP\src\Fortius.Amadeus.Air.RPC.Host\bin\Release" 

# 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:\Build\RPC\Fortius.RPC.AmadeusAir\WorldVentures.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

回答

0

你試圖在東西複製,而目的地的備用仍然有文件在使用。你是否檢查過這些/這些文件是否被鎖定?你已經停止了我看到的服務,你是否真的檢查過它是否成功?此外SysInternals有「處理」和「進程瀏覽器」,它們都可以檢查什麼是保持你的文件鎖定。

相關問題