4

I'm having Github workflow to run a python file. Before running the python file I want to swap user so that no sudo is required to execute the python file.

I tried with 'su' but it's says su must be run from command line. How to do that through Github Workflow. Thank you

.yaml

name: CI

on:
  push:
     branches: [ main ]

  workflow_dispatch:

jobs:
  build:
    runs-on: self-hosted
    strategy:
      matrix:
        python: [3.8.1]
        
    steps:
    - uses: actions/checkout@v2
    - name: Set up Python 
      uses: actions/setup-python@v2
      with:
        python-version: ${{ matrix.python }}
    - name: run multiple commands
      run: |
        echo $PWD
        whoami 
        su - user
        python helloworld.py


    
jessy
  • 51
  • 5
  • https://serverfault.com/a/44408/277950 also, are you sure you want your self-hosted runner to be running as root? – rethab Nov 24 '21 at 10:23
  • @rethab when I'm using the default user I'm getting **permissionError: [Errno 13] Permission** error. So I want to change to another user so that it may run python file. – jessy Nov 24 '21 at 10:28
  • which one is your default user? You should run the runner with a user that has write access to the workspace. – rethab Nov 24 '21 at 10:29
  • @rethab **mainuser** is the name of default user – jessy Nov 24 '21 at 10:37
  • assuming that `mainuser` is not root, can you give that user w+ permissions to the workspace? – rethab Nov 24 '21 at 10:51

0 Answers0