Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows script requires escape special chars to run successfully #7740

Open
windar022 opened this issue Mar 6, 2024 · 0 comments
Open

Windows script requires escape special chars to run successfully #7740

windar022 opened this issue Mar 6, 2024 · 0 comments
Labels
kind/bug Categorizes issue or PR as related to a bug.

Comments

@windar022
Copy link

windar022 commented Mar 6, 2024

Expected Behavior

Windows and Linux script should behave the same way when you are writing the scripts. Windows should not require to escape special chars.

Actual Behavior

Windows and Linux scripts are considering different validations about escaping chars

For example for windows you need to create the script as follow, if not the var are going to be added to the file as an empty value:

#!win powershell.exe -File
`$text="some value"
echo `$text

For Linux cases it is not necessary to keep escaping char, so the coding is more natural.

Steps to Reproduce the Problem

kind: Task
metadata:
  name: example-task-name
spec:
  steps:
    - name: powershell
      image: mcr.microsoft.com/powershell
      script: |
        #!win powershell.exe -File
        $text="some value"
        echo $text

Additional Info

A possible solution is to encode the script before create the file, like the non windows script logic https://github.com/tektoncd/pipeline/blob/main/pkg/pod/script.go#L189

When a script requires windows, the script can be encoded and then create the output file command like the following example:
https://github.com/tektoncd/pipeline/blob/main/pkg/pod/script.go#L177C3-L180C23

script = encodeScript(script)
initContainer.Args[1] += fmt.Sprintf(`[System.Text.Encoding]::UTF8.GetString([Convert]::FromBase64String("%s")) | Out-File -FilePath %s`, script, scriptFile)
  • Kubernetes version:

v1.27.9

  • Tekton Pipeline version:

v0.56.1

@windar022 windar022 added the kind/bug Categorizes issue or PR as related to a bug. label Mar 6, 2024
@windar022 windar022 changed the title Windows script requires escape chars to run successfully, Linux script does not Windows script requires escape special chars to run successfully Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug.
Projects
None yet
Development

No branches or pull requests

1 participant