I am using a fastlane Github action. I need to run it as the root user.
- name: Deploy
uses: maierj/[email protected]
with:
lane: 'alpha'
subdirectory: 'android-staging'
How can I run this as sudo?
As @itsjack mentioned, You either have to use SUDO_ASKPASS with a script that writes your sudoer user's password to the stream or use the actual echo command with sudo -S to make sudo read it from the pipeline.
I think it's much safer to store the password as a GitHub secret and echo it to the pipeline before using sudo -S; like this:
jobs:
Backup:
runs-on: self-hosted
steps:
- name: Backup
working-directory: ${{ secrets.PRODUCTIONWEBROOT }}
run: echo ${{ secrets.USERPWD }} | sudo -S tar czf ./tmp/${{ format('Backup_Before_{0}.tar.gz', github.run_id) }} ./wwwroot
You can even use sudo as a user like www-data if you want:
jobs:
Backup:
runs-on: self-hosted
steps:
- name: Backup
working-directory: ${{ secrets.PRODUCTIONWEBROOT }}
run: echo ${{ secrets.USERPWD }} | sudo -S -u www-data tar czf ./tmp/${{ format('Backup_Before_{0}.tar.gz', github.run_id) }} ./wwwroot
REMEMBER: the USERPWD secret must be the password to the user who runs Github's self-hosted service. I mean the user you used to install the runner or the specific user you used to install the runner service using .svc.sh install USERNAME
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With