change backslashes to forward slashes in powershell provisioner; was breaking with cygwin

This commit is contained in:
Megan Marsh 2018-03-05 14:18:23 -08:00
parent 043a57be21
commit 3faf73b5f3
2 changed files with 10 additions and 10 deletions

View File

@ -397,7 +397,7 @@ func (p *Provisioner) uploadEnvVars(flattenedEnvVars string) (envVarPath string,
// 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
envVarReader := strings.NewReader(flattenedEnvVars) envVarReader := strings.NewReader(flattenedEnvVars)
uuid := uuid.TimeOrderedUUID() uuid := uuid.TimeOrderedUUID()
envVarPath = fmt.Sprintf(`${env:SYSTEMROOT}\Temp\packer-env-vars-%s.ps1`, uuid) envVarPath = fmt.Sprintf(`${env:SYSTEMROOT}/Temp/packer-env-vars-%s.ps1`, uuid)
log.Printf("Uploading env vars to %s", envVarPath) log.Printf("Uploading env vars to %s", envVarPath)
err = p.communicator.Upload(envVarPath, envVarReader, nil) err = p.communicator.Upload(envVarPath, envVarReader, nil)
if err != nil { if err != nil {
@ -482,7 +482,7 @@ func (p *Provisioner) generateElevatedRunner(command string) (uploadedPath strin
// Only use %ENVVAR% format for environment variables when setting // Only use %ENVVAR% format for environment variables when setting
// the log file path; Do NOT use $env:ENVVAR format as it won't be // the log file path; Do NOT use $env:ENVVAR format as it won't be
// expanded correctly in the elevatedTemplate // expanded correctly in the elevatedTemplate
logFile := `%SYSTEMROOT%\Temp\` + taskName + ".out" logFile := `%SYSTEMROOT%/Temp/` + taskName + ".out"
command += fmt.Sprintf(" > %s 2>&1", logFile) command += fmt.Sprintf(" > %s 2>&1", logFile)
// elevatedTemplate wraps the command in a single quoted XML text // elevatedTemplate wraps the command in a single quoted XML text
@ -524,7 +524,7 @@ func (p *Provisioner) generateElevatedRunner(command string) (uploadedPath strin
return "", err return "", err
} }
uuid := uuid.TimeOrderedUUID() uuid := uuid.TimeOrderedUUID()
path := fmt.Sprintf(`${env:TEMP}\packer-elevated-shell-%s.ps1`, uuid) path := fmt.Sprintf(`${env:TEMP}/packer-elevated-shell-%s.ps1`, uuid)
log.Printf("Uploading elevated shell wrapper for command [%s] to [%s]", command, path) log.Printf("Uploading elevated shell wrapper for command [%s] to [%s]", command, path)
err = p.communicator.Upload(path, &buffer, nil) err = p.communicator.Upload(path, &buffer, nil)
if err != nil { if err != nil {
@ -532,6 +532,6 @@ func (p *Provisioner) generateElevatedRunner(command string) (uploadedPath strin
} }
// CMD formatted Path required for this op // CMD formatted Path required for this op
path = fmt.Sprintf("%s-%s.ps1", "%TEMP%\\packer-elevated-shell", uuid) path = fmt.Sprintf("%s-%s.ps1", "%TEMP%/packer-elevated-shell", uuid)
return path, err return path, err
} }

View File

@ -414,7 +414,7 @@ func TestProvisionerProvision_Inline(t *testing.T) {
} }
cmd := comm.StartCmd.Command cmd := comm.StartCmd.Command
re := regexp.MustCompile(`powershell -executionpolicy bypass "& { if \(Test-Path variable:global:ProgressPreference\){\$ProgressPreference='SilentlyContinue'};\. \${env:SYSTEMROOT}\\Temp\\packer-env-vars-[[:alnum:]]{8}-[[:alnum:]]{4}-[[:alnum:]]{4}-[[:alnum:]]{4}-[[:alnum:]]{12}\.ps1; &'c:/Windows/Temp/inlineScript.ps1';exit \$LastExitCode }"`) re := regexp.MustCompile(`powershell -executionpolicy bypass "& { if \(Test-Path variable:global:ProgressPreference\){\$ProgressPreference='SilentlyContinue'};\. \${env:SYSTEMROOT}/Temp/packer-env-vars-[[:alnum:]]{8}-[[:alnum:]]{4}-[[:alnum:]]{4}-[[:alnum:]]{4}-[[:alnum:]]{12}\.ps1; &'c:/Windows/Temp/inlineScript.ps1';exit \$LastExitCode }"`)
matched := re.MatchString(cmd) matched := re.MatchString(cmd)
if !matched { if !matched {
t.Fatalf("Got unexpected command: %s", cmd) t.Fatalf("Got unexpected command: %s", cmd)
@ -434,7 +434,7 @@ func TestProvisionerProvision_Inline(t *testing.T) {
} }
cmd = comm.StartCmd.Command cmd = comm.StartCmd.Command
re = regexp.MustCompile(`powershell -executionpolicy bypass "& { if \(Test-Path variable:global:ProgressPreference\){\$ProgressPreference='SilentlyContinue'};\. \${env:SYSTEMROOT}\\Temp\\packer-env-vars-[[:alnum:]]{8}-[[:alnum:]]{4}-[[:alnum:]]{4}-[[:alnum:]]{4}-[[:alnum:]]{12}\.ps1; &'c:/Windows/Temp/inlineScript.ps1';exit \$LastExitCode }"`) re = regexp.MustCompile(`powershell -executionpolicy bypass "& { if \(Test-Path variable:global:ProgressPreference\){\$ProgressPreference='SilentlyContinue'};\. \${env:SYSTEMROOT}/Temp/packer-env-vars-[[:alnum:]]{8}-[[:alnum:]]{4}-[[:alnum:]]{4}-[[:alnum:]]{4}-[[:alnum:]]{12}\.ps1; &'c:/Windows/Temp/inlineScript.ps1';exit \$LastExitCode }"`)
matched = re.MatchString(cmd) matched = re.MatchString(cmd)
if !matched { if !matched {
t.Fatalf("Got unexpected command: %s", cmd) t.Fatalf("Got unexpected command: %s", cmd)
@ -461,7 +461,7 @@ func TestProvisionerProvision_Scripts(t *testing.T) {
} }
cmd := comm.StartCmd.Command cmd := comm.StartCmd.Command
re := regexp.MustCompile(`powershell -executionpolicy bypass "& { if \(Test-Path variable:global:ProgressPreference\){\$ProgressPreference='SilentlyContinue'};\. \${env:SYSTEMROOT}\\Temp\\packer-env-vars-[[:alnum:]]{8}-[[:alnum:]]{4}-[[:alnum:]]{4}-[[:alnum:]]{4}-[[:alnum:]]{12}\.ps1; &'c:/Windows/Temp/script.ps1';exit \$LastExitCode }"`) re := regexp.MustCompile(`powershell -executionpolicy bypass "& { if \(Test-Path variable:global:ProgressPreference\){\$ProgressPreference='SilentlyContinue'};\. \${env:SYSTEMROOT}/Temp/packer-env-vars-[[:alnum:]]{8}-[[:alnum:]]{4}-[[:alnum:]]{4}-[[:alnum:]]{4}-[[:alnum:]]{12}\.ps1; &'c:/Windows/Temp/script.ps1';exit \$LastExitCode }"`)
matched := re.MatchString(cmd) matched := re.MatchString(cmd)
if !matched { if !matched {
t.Fatalf("Got unexpected command: %s", cmd) t.Fatalf("Got unexpected command: %s", cmd)
@ -495,7 +495,7 @@ func TestProvisionerProvision_ScriptsWithEnvVars(t *testing.T) {
} }
cmd := comm.StartCmd.Command cmd := comm.StartCmd.Command
re := regexp.MustCompile(`powershell -executionpolicy bypass "& { if \(Test-Path variable:global:ProgressPreference\){\$ProgressPreference='SilentlyContinue'};\. \${env:SYSTEMROOT}\\Temp\\packer-env-vars-[[:alnum:]]{8}-[[:alnum:]]{4}-[[:alnum:]]{4}-[[:alnum:]]{4}-[[:alnum:]]{12}\.ps1; &'c:/Windows/Temp/script.ps1';exit \$LastExitCode }"`) re := regexp.MustCompile(`powershell -executionpolicy bypass "& { if \(Test-Path variable:global:ProgressPreference\){\$ProgressPreference='SilentlyContinue'};\. \${env:SYSTEMROOT}/Temp/packer-env-vars-[[:alnum:]]{8}-[[:alnum:]]{4}-[[:alnum:]]{4}-[[:alnum:]]{4}-[[:alnum:]]{12}\.ps1; &'c:/Windows/Temp/script.ps1';exit \$LastExitCode }"`)
matched := re.MatchString(cmd) matched := re.MatchString(cmd)
if !matched { if !matched {
t.Fatalf("Got unexpected command: %s", cmd) t.Fatalf("Got unexpected command: %s", cmd)
@ -612,7 +612,7 @@ func TestProvision_createCommandText(t *testing.T) {
// Non-elevated // Non-elevated
cmd, _ := p.createCommandText() cmd, _ := p.createCommandText()
re := regexp.MustCompile(`powershell -executionpolicy bypass "& { if \(Test-Path variable:global:ProgressPreference\){\$ProgressPreference='SilentlyContinue'};\. \${env:SYSTEMROOT}\\Temp\\packer-env-vars-[[:alnum:]]{8}-[[:alnum:]]{4}-[[:alnum:]]{4}-[[:alnum:]]{4}-[[:alnum:]]{12}\.ps1; &'c:/Windows/Temp/script.ps1';exit \$LastExitCode }"`) re := regexp.MustCompile(`powershell -executionpolicy bypass "& { if \(Test-Path variable:global:ProgressPreference\){\$ProgressPreference='SilentlyContinue'};\. \${env:SYSTEMROOT}/Temp/packer-env-vars-[[:alnum:]]{8}-[[:alnum:]]{4}-[[:alnum:]]{4}-[[:alnum:]]{4}-[[:alnum:]]{12}\.ps1; &'c:/Windows/Temp/script.ps1';exit \$LastExitCode }"`)
matched := re.MatchString(cmd) matched := re.MatchString(cmd)
if !matched { if !matched {
t.Fatalf("Got unexpected command: %s", cmd) t.Fatalf("Got unexpected command: %s", cmd)
@ -645,7 +645,7 @@ func TestProvision_uploadEnvVars(t *testing.T) {
t.Fatalf("Failed to upload env var file") t.Fatalf("Failed to upload env var file")
} }
re := regexp.MustCompile(`\${env:SYSTEMROOT}\\Temp\\packer-env-vars-[[:alnum:]]{8}-[[:alnum:]]{4}-[[:alnum:]]{4}-[[:alnum:]]{4}-[[:alnum:]]{12}\.ps1`) re := regexp.MustCompile(`\${env:SYSTEMROOT}/Temp/packer-env-vars-[[:alnum:]]{8}-[[:alnum:]]{4}-[[:alnum:]]{4}-[[:alnum:]]{4}-[[:alnum:]]{12}\.ps1`)
matched := re.MatchString(envVarPath) matched := re.MatchString(envVarPath)
if !matched { if !matched {
t.Fatalf("Got unexpected path for env var file: %s", envVarPath) t.Fatalf("Got unexpected path for env var file: %s", envVarPath)