From e0bcba491358347aafc6ba2d422ea3c485d19eec Mon Sep 17 00:00:00 2001 From: DanHam Date: Fri, 15 Jun 2018 00:09:50 +0100 Subject: [PATCH] Make the upload of env vars retryable in case of restarts --- provisioner/powershell/provisioner.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/provisioner/powershell/provisioner.go b/provisioner/powershell/provisioner.go index 6eb9c5572..8f749ef7c 100644 --- a/provisioner/powershell/provisioner.go +++ b/provisioner/powershell/provisioner.go @@ -426,12 +426,20 @@ func (p *Provisioner) createFlattenedEnvVars(elevated bool) (flattened string) { } func (p *Provisioner) uploadEnvVars(flattenedEnvVars string) (err error) { - // Upload all env vars to a powershell script on the target build file system + // Upload all env vars to a powershell script on the target build file + // system. Do this in the context of a single retryable function so + // that we gracefully handle any errors created by transient conditions + // such as a system restart envVarReader := strings.NewReader(flattenedEnvVars) log.Printf("Uploading env vars to %s", p.config.RemoteEnvVarPath) - err = p.communicator.Upload(p.config.RemoteEnvVarPath, envVarReader, nil) + err = p.retryable(func() error { + if err := p.communicator.Upload(p.config.RemoteEnvVarPath, envVarReader, nil); err != nil { + return fmt.Errorf("Error uploading ps script containing env vars: %s", err) + } + return err + }) if err != nil { - return fmt.Errorf("Error uploading ps script containing env vars: %s", err) + return err } return }