From cbee767cbced1d4a9ab6f72c184616d89a38ffb8 Mon Sep 17 00:00:00 2001 From: karthik P Date: Tue, 3 Jun 2025 22:09:49 +0530 Subject: [PATCH] adding new line character to each written command. --- provisioner/powershell/provisioner.go | 8 ++++---- .../test-fixtures/powershell-inline-provisioner.txt | 10 ++++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/provisioner/powershell/provisioner.go b/provisioner/powershell/provisioner.go index 88b9151a6..1769bff52 100644 --- a/provisioner/powershell/provisioner.go +++ b/provisioner/powershell/provisioner.go @@ -313,7 +313,7 @@ func extractInlineScript(p *Provisioner) (string, error) { // we concatenate all the inline commands for _, command := range p.config.Inline { log.Printf("Found command: %s", command) - if _, err := commandBuilder.WriteString(command); err != nil { + if _, err := commandBuilder.WriteString(command + "\n"); err != nil { return "", fmt.Errorf("failed to wrap script contents: %w", err) } } @@ -344,9 +344,11 @@ func (p *Provisioner) Provision(ctx context.Context, ui packersdk.Ui, comm packe p.generatedData = generatedData var scripts []string - + // maps temp script paths to original script paths + tempToOriginalScriptMap := make(map[string]string) if p.config.Inline != nil { temp, err := extractInlineScript(p) + tempToOriginalScriptMap[temp] = temp if err != nil { ui.Error(fmt.Sprintf("Unable to extract inline scripts into a file: %s", err)) } @@ -354,8 +356,6 @@ func (p *Provisioner) Provision(ctx context.Context, ui packersdk.Ui, comm packe // Remove temp script containing the inline commands when done defer os.Remove(temp) } - // maps temp script paths to original script paths - tempToOriginalScriptMap := make(map[string]string, len(p.config.Scripts)) if len(p.config.Scripts) > 0 { diff --git a/provisioner/powershell/test-fixtures/powershell-inline-provisioner.txt b/provisioner/powershell/test-fixtures/powershell-inline-provisioner.txt index 1b63c1742..75ade524a 100644 --- a/provisioner/powershell/test-fixtures/powershell-inline-provisioner.txt +++ b/provisioner/powershell/test-fixtures/powershell-inline-provisioner.txt @@ -1,8 +1,10 @@ { "type": "powershell", - "environment_vars": "PackerRunUUID={{build `PackerRunUUID`}},ID={{build `ID`}}", + "environment_vars": "PackerRunUUID={{build `PackerRunUUID`}},ID={{build `ID`}},TEST_ENV_VAR=TestValue", "inline": [ - "Write-Host \"$env:ID for provisioner.$env:PackerRunUUID\"" + "Write-Host \"$env:ID for provisioner.$env:PackerRunUUID build_name: $env:packer_build_name, test_env_var: $env:test_env_var\"", + "setx BUILD_AMI_VERSION \"1.0.0\"", + "setx BUILD_AMI_NAME custom_ami_name", + "setx BUILD_AMI_DESCRIPTION \"This is a custom AMI created for testing purposes\"" ] -} - +} \ No newline at end of file