resticprofile
resticprofile copied to clipboard
Windows variables
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 ?
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.
%ERROR_EXIT_CODE% works correclty, but %ERROR_STDERR% not. Whether resticprofile can set the same variables on both systems ?
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).
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.
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%"
Great, thank you for your time and effort.
Fixed in v0.18.0 (https://github.com/creativeprojects/resticprofile/releases/tag/v0.18.0)