Skip to content

Commit

Permalink
Attempt at retrying choco install (elastic#5764)
Browse files Browse the repository at this point in the history
  • Loading branch information
rowlandgeoff authored Oct 13, 2024
1 parent a24fe4f commit d6da7eb
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions pkg/testing/windows/windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ func (WindowsRunner) Prepare(ctx context.Context, sshClient ssh.SSHClient, logge
// install chocolatey
logger.Logf("Installing chocolatey")
chocoInstall := `"[System.Net.ServicePointManager]::SecurityProtocol = 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))"`
stdOut, errOut, err := sshRunPowershell(ctx, sshClient, chocoInstall)
updateCtx, updateCancel := context.WithTimeout(ctx, 3*time.Minute)
defer updateCancel()
stdOut, errOut, err := sshRunPowershell(updateCtx, sshClient, chocoInstall)
if err != nil {
return fmt.Errorf("failed to install chocolatey: %w (stdout: %s, stderr: %s)", err, stdOut, errOut)
}
Expand Down Expand Up @@ -236,12 +238,12 @@ func (WindowsRunner) Diagnostics(ctx context.Context, sshClient ssh.SSHClient, l
}

func sshRunPowershell(ctx context.Context, sshClient ssh.SSHClient, cmd string) ([]byte, []byte, error) {
return sshClient.Exec(ctx, "powershell", []string{
return sshClient.ExecWithRetry(ctx, "powershell", []string{
"-NoProfile",
"-InputFormat", "None",
"-ExecutionPolicy", "Bypass",
"-Command", cmd,
}, nil)
}, 15*time.Second)
}

func toPowershellScript(agentVersion string, prefix string, verbose bool, tests []string, env map[string]string) string {
Expand Down

0 comments on commit d6da7eb

Please sign in to comment.