Generic wrapper for retry

Sanemat's Avatar


10 Sep, 2015 04:01 PM

I'm a nodejs user, I met a lot of network error during npm install.
I hope a generic wrapper for retry.

nuget restore has nuge-restore.cmd. nuget#restore-with-retries But this is only for nuget restore.

I copied and pasted windows_retry.cmd and Execute-With-Retry.ps1. I use this.

I'm not familiar with cmd and powershell yet, so I hope appveyor provides a retry command. What do you think about a generic wrapper for retry?

Travis-ci has travis_retry command.

  1. 1 Posted by Chris on 09 Aug, 2016 03:14 PM

    Chris's Avatar

    +1, would also like this.

    I found this example code, am thinking of adding it to my appveyor:

    But I don't completely understand it :-/

    function Retry-Command
        param (
        [Parameter(Mandatory=$false)][int]$retries = 5,
        [Parameter(Mandatory=$false)][int]$secondsDelay = 2
        # Setting ErrorAction to Stop is important. This ensures any errors that occur in the command are
        # treated as terminating errors, and will be caught by the catch block.
        $args.ErrorAction = "Stop"
        $retrycount = 0
        $completed = $false

        while (-not $completed) {
            try {
                & $command @args
                Write-Verbose ("Command [{0}] succeeded." -f $command)
                $completed = $true
            } catch {
                if ($retrycount -ge $retries) {
                    Write-Verbose ("Command [{0}] failed the maximum number of {1} times." -f $command, $retrycount)
                } else {
                    Write-Verbose ("Command [{0}] failed. Retrying in {1} seconds." -f $command, $secondsDelay)
                    Start-Sleep $secondsDelay

  2. 2 Posted by Ilya Finkelshte... on 09 Aug, 2016 04:12 PM

    Ilya Finkelshteyn's Avatar

    Hi Chris,

    We actually already have appveyor-retry command. Please give it a try.
    Please note that to call npm, now you need to use the following syntax: appveyor-retry call npm install
    We understand that it is not obvious, and fix is on its way, in a few days you will be able to use just: appveyor-retry npm install

    Thank you,

  3. 3 Posted by Sanemat on 20 Aug, 2016 12:53 AM

    Sanemat's Avatar

    Hi Ilya,

    I have a question.
    I try to do below, but this does not work fine.

      - nodejs_version: 4
    - ps: appveyor-retry Install-Product node $env:nodejs_version

    This brings error:

    appveyor-retry : 'Install-Product' is not recognized as an internal or external command,

    Do you have any suggestions?

  4. 4 Posted by Ilya Finkelshte... on 20 Aug, 2016 10:25 PM

    Ilya Finkelshteyn's Avatar

    Please use - cmd: appveyor-retry powershell Install-Product node $env:nodejs_version
    This is because appveyor-retry is cmd batch, which expects some exe to be called, not PowerShell function (which install-product is). Sorry for confusion.

  5. Ilya Finkelshteyn closed this discussion on 25 Aug, 2018 02:08 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac