Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding chocolatey retry logic #1163

Merged
merged 3 commits into from
May 11, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions .expeditor/publish_to_chocolatey.ps1
Original file line number Diff line number Diff line change
@@ -1,8 +1,31 @@
$ErrorActionPreference="stop"

Write-Host "--- Fetching latest release data from omnitruck API"
$Uri = "https://omnitruck.chef.io/stable/chef-workstation/metadata?p=windows&pv=2016&m=x86_64&v=latest"
$releaseRecord = Invoke-RestMethod -Uri $Uri -Headers @{accept="application/json"} -ErrorAction Stop
$version = "$Env:EXPEDITOR_VERSION"
$secondsDelay = 20 # seconds
$retries = 60 # retry for up to 20 minutes
$completed = $false
$retrycount = 0

Write-Host "--- Fetching version $version data from omnitruck API"
$Uri = "https://omnitruck.chef.io/stable/chef-workstation/metadata?p=windows&pv=2016&m=x86_64&v=$version"

while (-not $completed) {
try {
$releaseRecord = Invoke-RestMethod -Uri $Uri -Headers @{accept="application/json"} -ErrorAction Stop
$completed = $?
} catch {
if ($retrycount -ge $retries) {
throw "Fetching version $version failed the maximum number of $retrycount times."
} else {
Write-Host "Fetching version $version failed. Retrying in $secondsDelay seconds."
Start-Sleep $secondsDelay
$retrycount++
}
}
}

Write-Host "Successfully fetched version $version information"
Write-Host ("URL: {0}" -f $releaseRecord.url)

Write-Host "--- Copying templates locally"
$tempDir = Join-Path $env:temp ([System.IO.Path]::GetRandomFileName())
Expand Down