Skip to content

Commit

Permalink
Robocopy hotfix (#4837)
Browse files Browse the repository at this point in the history
  • Loading branch information
ericsciple authored Jul 20, 2017
1 parent f7e3842 commit 23083dd
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions Tasks/PublishBuildArtifacts/Invoke-Robocopy.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@ $writer = New-Object System.IO.StreamWriter($stdout, $utf8)
# All subsequent output must be written using [System.Console]::WriteLine(). In
# PowerShell 4, Write-Host and Out-Default do not consider the updated stream writer.

# Print the ##command.
[System.Console]::WriteLine("##[command]robocopy.exe /E /COPY:DA /NP /R:3 /MT:$ParallelCount `"$Source`" `"$Target`" *")
# Print the ##command. The /MT parameter is only supported on 2008 R2 and higher.
if ($ParallelCount -gt 1) {
[System.Console]::WriteLine("##[command]robocopy.exe /E /COPY:DA /NP /R:3 /MT:$ParallelCount `"$Source`" `"$Target`" *")
} else {
[System.Console]::WriteLine("##[command]robocopy.exe /E /COPY:DA /NP /R:3 `"$Source`" `"$Target`" *")
}

# The $OutputEncoding variable instructs PowerShell how to interpret the output
# from the external command.
Expand All @@ -59,15 +63,30 @@ $OutputEncoding = [System.Text.Encoding]::Default
#
# Note, the output from robocopy needs to be iterated over. Otherwise PowerShell.exe
# will launch the external command in such a way that it inherits the streams.
& robocopy.exe /E /COPY:DA /NP /R:3 /MT:$ParallelCount $Source $Target * 2>&1 |
ForEach-Object {
if ($_ -is [System.Management.Automation.ErrorRecord]) {
[System.Console]::WriteLine($_.Exception.Message)
#
# Note, the /MT parameter is only supported on 2008 R2 and higher.
if ($ParallelCount -gt 1) {
& robocopy.exe /E /COPY:DA /NP /R:3 /MT:$ParallelCount $Source $Target * 2>&1 |
ForEach-Object {
if ($_ -is [System.Management.Automation.ErrorRecord]) {
[System.Console]::WriteLine($_.Exception.Message)
}
else {
[System.Console]::WriteLine($_)
}
}
else {
[System.Console]::WriteLine($_)
} else {
& robocopy.exe /E /COPY:DA /NP /R:3 $Source $Target * 2>&1 |
ForEach-Object {
if ($_ -is [System.Management.Automation.ErrorRecord]) {
[System.Console]::WriteLine($_.Exception.Message)
}
else {
[System.Console]::WriteLine($_)
}
}
}
}

[System.Console]::WriteLine("##[debug]robocopy exit code '$LASTEXITCODE'")
[System.Console]::Out.Flush()
if ($LASTEXITCODE -ge 8) {
Expand Down

0 comments on commit 23083dd

Please sign in to comment.