TLDR: Use $ErrorActionPreference = "Stop" so the agent knows one of the script's command failed.
Found the root cause, but I forget to post it here. Despite several issues and discussions on winget-cli's github suggesting it can be run in system context it turns out that it is in fact impossible. So when i tried to execute it with the agent it returned instantly with a non zero exit code, but the ps script returned normally due to the lack of $ErrorActionPreference = "Stop" which would have caused the agent to recognise the script had failed.
For now I'll use chocolatey with a custom caching proxy that rewrites packages - so even external resources can be cached locally by nginx - until MS figures out how to create a usable package manager.
P.S.
Thank you for the tip about auto termination, I'll keep that in mind. Also sorry for the late reply.
Found the root cause, but I forget to post it here. Despite several issues and discussions on winget-cli's github suggesting it can be run in system context it turns out that it is in fact impossible. So when i tried to execute it with the agent it returned instantly with a non zero exit code, but the ps script returned normally due to the lack of $ErrorActionPreference = "Stop" which would have caused the agent to recognise the script had failed.
For now I'll use chocolatey with a custom caching proxy that rewrites packages - so even external resources can be cached locally by nginx - until MS figures out how to create a usable package manager.
P.S.
Thank you for the tip about auto termination, I'll keep that in mind. Also sorry for the late reply.