Skip to content

Commit 879c48d

Browse files
authored
Retry code mirror (dotnet#4605)
Retry if mirror fails, unless it fails due to upstream commits.
1 parent 5110206 commit 879c48d

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

azure-pipelines-code-mirror.yml

+38-3
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,45 @@ jobs:
4242
git reset --hard origin/$(BranchToMirror)
4343
displayName: Hard reset local branch to GitHub branch
4444
workingDirectory: $(WorkingDirectoryName)
45-
- script: |
46-
git push azdo-mirror $(BranchToMirror) $(ExtraPushArgs)
45+
- task: PowerShell@2
4746
displayName: Push changes to Azure DevOps repo
48-
workingDirectory: $(WorkingDirectoryName)
47+
inputs:
48+
targetType: inline
49+
workingDirectory: $(WorkingDirectoryName)
50+
script: |
51+
git push azdo-mirror $(BranchToMirror) $(ExtraPushArgs)
52+
53+
if ($LASTEXITCODE -EQ 0) {
54+
Write-Host "Push was successful"
55+
exit
56+
}
57+
58+
git fetch azdo-mirror
59+
git fetch origin
60+
$commits = (git --no-pager rev-list origin/$(BranchToMirror)..azdo-mirror/$(BranchToMirror) | Measure-Object -line).Lines
61+
if ($commits -NE 0) {
62+
Write-Host "##vso[task.LogIssue type=error;]Mirror repository $(AzDORepoName) has unexpected commits"
63+
git --no-pager log origin/$(BranchToMirror)..azdo-mirror/$(BranchToMirror)
64+
exit 1
65+
}
66+
67+
Write-Host "##vso[task.LogIssue type=warning;]Push failed for unknown reason"
68+
69+
$retryattempt=0
70+
while ($retryattempt -LT 3) {
71+
$retryattempt+=1
72+
Write-Host "Retry attempt $retryattempt of 3 in 5 seconds..."
73+
Start-Sleep -Seconds 5
74+
75+
git push azdo-mirror $(BranchToMirror) $(ExtraPushArgs)
76+
if ($LASTEXITCODE -EQ 0) {
77+
Write-Host "Push successful"
78+
exit
79+
}
80+
}
81+
82+
Write-Host "##vso[task.LogIssue type=error;]git failed to push to Azure DevOps mirror"
83+
exit 1
4984
5085
- task: PowerShell@1
5186
displayName: Broadcast target, branch, commit in metadata

0 commit comments

Comments
 (0)