appveyor / ci

AppVeyor community support repository
https://www.appveyor.com
344 stars 65 forks source link

Add an option to start powershell with sudo on linux #2193

Open TylerLeonhardt opened 6 years ago

TylerLeonhardt commented 6 years ago

I'm loving the new Ubuntu builds - I'm also loving that powershell comes on the build already!

I'd love an option to start powershell with sudo on linux.

For example, lets say myscript.ps1 requires su permissions for something (running Install-Module without -Scope CurrentUser is a real example: - ps: myscript.ps1

the myscript.ps1 is run in a non-sudo'd pwsh process and so it fails. The only way to run a sudo'd powershell command is to have a line that does something like this: - sh: sudo pwsh myscript.ps1

That's a good workaround, although that does have a problem that it creates a new runspace every time.

That is to say, I can't:

- sh: sudo pwsh yourscript.ps1
- sh: sudo pwsh yourscript2.ps1

And the scripts will be executed in the same runspace.

There should be a flag that allows pwsh to be run with sudo so that:

- ps: myscript.ps1
- ps: myscript2.ps1

run in the same runspace with su permissions.

Note: PowerShell is working on supporting sudo at the cmdlet level: sudo Install-Module foo

https://github.com/PowerShell/PowerShell/issues/3232

That said, it's possibly a year out. Plus there's still utility in a pwsh launched with sudo even when this feature comes out so you don't have to special case your scripts with:

if($IsLinux) {
    sudo foo
} else {
   foo
}
IlyaFinkelshteyn commented 6 years ago

Workaround for common runspace. Not exactly super-elegant but should work :)

- sh: echo ".\myscript.ps1; .\myscript2.ps1" > run-both.ps1
- sh: sudo pwsh run-both.ps1