provisioner/powershell: Update cleanup logic

This change reduces the retry timeout from 5m to 1m, and sets the
RetryDelay to 10s for a total of 6 retries. In additional to the retry
time reduction the cleanup script will now check to see if the
provisioner script created by Packer exists before trying to delete to
prevent any file not found issues.

Closes #9181
Closes #9189
This commit is contained in:
Wilken Rivera 2020-05-14 10:14:01 -04:00
parent df3bac3104
commit c330d2f04c
1 changed files with 4 additions and 4 deletions

View File

@ -335,10 +335,10 @@ func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.C
return nil
}
err := retry.Config{StartTimeout: p.config.StartRetryTimeout}.Run(ctx, func(ctx context.Context) error {
err := retry.Config{StartTimeout: time.Minute, RetryDelay: func() time.Duration { return 10 * time.Second }}.Run(ctx, func(ctx context.Context) error {
command, err := p.createRemoteCleanUpCommand(uploadedScripts)
if err != nil {
log.Printf("failed to create a remote cleanup script: %s", err)
log.Printf("failed to upload the remote cleanup script: %q", err)
return err
}
@ -346,7 +346,7 @@ func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.C
return cmd.RunWithUi(ctx, comm, ui)
})
if err != nil {
log.Printf("failed to clean up temporary files: %s", strings.Join(uploadedScripts, ","))
log.Printf("remote cleanup script failed to upload; skipping the removal of temporary files: %s; ", strings.Join(uploadedScripts, ","))
}
return nil
@ -364,7 +364,7 @@ func (p *Provisioner) createRemoteCleanUpCommand(remoteFiles []string) (string,
remotePath := p.config.remoteCleanUpScriptPath
remoteFiles = append(remoteFiles, remotePath)
for _, filename := range remoteFiles {
fmt.Fprintf(&b, "Remove-Item %s\n", filename)
fmt.Fprintf(&b, "if (Test-Path %[1]s) {Remove-Item %[1]s}\n", filename)
}
if err := p.communicator.Upload(remotePath, strings.NewReader(b.String()), nil); err != nil {