More robust command execution on Windows
There's currently several issues with command execution:
- on windows we use
iex, which in some cases may require careful escaping to work correctly - the script is saved in an environment variable
CI_SCRIPTand may exceed length limits (32K on windows I think and 2mb on linux, for both args and env vars... I haven't tested in detail yet) - the
+ cmdprint command works poorly with odd strings (especially on windows)
A prior attempt at fixing 1 was at https://github.com/woodpecker-ci/woodpecker/pull/6969 but it actually made point 2 worse.
1 can be fixed by feeding the actual script via stdin to the shell. This is already implemented for libvirt and ssh in my libvirt wip patch: https://github.com/woodpecker-ci/woodpecker/pull/6985 I don't feel comfortable at the moment to implement this for docker and kubernetes, since I'm not very familiar with those backends yet and it would sidetrack my libvirt work.
If we feed the script via stdin, we also don't really need the env variable anymore, I guess. That would be a breaking change potentially though and open the question on how to debug the script as a whole.
I have had success with fixing 3 via heredoc, e.g.:
- windows:
const traceScriptWin = ` Write-Output @' + %s '@ & { %s ; if ($LASTEXITCODE) { exit $LASTEXITCODE } ; } ; ` - posix:
const traceScript = ` cat <<'WOODPECKER_EOF' + %s WOODPECKER_EOF { %s } `
Source: woodpecker-ci/woodpecker