resticprofile icon indicating copy to clipboard operation
resticprofile copied to clipboard

Windows variables

Open tj57 opened this issue 3 years ago • 6 comments

This command:

run-after-fail: - "curl -fsS --retry 3 --data-raw \"$ERROR_STDERR\" https://healthchecks.mydomain/ping/4b2fef02-0ccf-ff/$ERROR_EXIT_CODE"

works correcly under linux, but with windows not. I tested $ERROR_STDERR, $ERROR_EXIT_CODE, %errorlevel%

Can variables in windows be the same as in linux ?

tj57 avatar May 26 '22 06:05 tj57

resticprofile uses a shell to execute commands, therefore the commands follow the syntax of the native shell.

In Windows env variables are referenced with % ERROR_EXIT_CODE% when the default shell (cmd.exe) is used.

With Power Shell the variable syntax would be $Env:ERROR_EXIT_CODE. But checking the implementation this is no config option at the moment resticprofile will always use the default shell of an OS.

Maybe we could make this a choice to have a more predictable behavior.

jkellerer avatar May 26 '22 06:05 jkellerer

%ERROR_EXIT_CODE% works correclty, but %ERROR_STDERR% not. Whether resticprofile can set the same variables on both systems ?

tj57 avatar May 26 '22 08:05 tj57

The variables are the same but the way how they are handled may differ depending on the shell. E. g. I’m not sure if cmd.exe would tolerate variable values with newlines (like in stderr).

jkellerer avatar May 26 '22 09:05 jkellerer

While testing #112, I found on windows default shell (cmd.exe), double quotes are not properly escaped. You may have better results with single quotes instead. E.g.: "curl -fsS --retry 3 --data-raw '%ERROR_STDERR%' https://healthchecks.mydomain/ping/4b2fef02-0ccf-ff/%ERROR_EXIT_CODE%"

But also in this case multiline is an issue. Using a small (batch) script (that also has access to env variables) may work around this.

jkellerer avatar May 26 '22 14:05 jkellerer

When #112 is merged the following should work even with multiline and without requiring powershell since the PR will set EnableDelayedExpansion on cmd.exe and this enables !variable! syntax:

"curl -fsS --retry 3 --data-raw '!ERROR_STDERR!' https://healthchecks.mydomain/ping/4b2fef02-0ccf-ff/%ERROR_EXIT_CODE%"

jkellerer avatar May 26 '22 15:05 jkellerer

Great, thank you for your time and effort.

tj57 avatar May 31 '22 04:05 tj57

Fixed in v0.18.0 (https://github.com/creativeprojects/resticprofile/releases/tag/v0.18.0)

creativeprojects avatar Aug 29 '22 19:08 creativeprojects