DEV Community

Cover image for GitHub Actions: Fixing the 'Permission Denied' error for shell scripts
Aileen Rae
Aileen Rae

Posted on • Originally published at aileenrae.co.uk

GitHub Actions: Fixing the 'Permission Denied' error for shell scripts

Ever encountered this frustratingly vague "Permission denied" error when trying to run a bash script in an GitHub action workflow? 😑

Screenshot from GitHub's 'Actions' tab showing a build error: 'Permission denied' when trying to run a shell script

"Permission denied" means that your script file does not have the "execute" permission set. On Mac and Linux you can use the chmod command to make script files executable, but Windows does not support this.

How to fix it

Luckily, Git offers a command that works with Windows. Run:

git update-index --chmod=+x your_script.sh
Enter fullscreen mode Exit fullscreen mode

locally to make the bash script executable. Once you commit and push the change to your GitHub repository the script will be allowed to run in your GitHub action. πŸŽ‰

NB: you will need to run this command then commit and push the change to GitHub for any bash script you create or rename on a Windows machine in order for it to run in a GitHub action.

How to run a bash script in a GitHub action

That's great Aileen, but how do I even add a script to a GitHub action?

Here is an example action which runs a your_script.sh script on commit to the main branch of your repository.

# https://gist.github.com/aileen-r/f74e680fb47ebc8b29a9f1cc452a5da9

# This is a basic workflow to help you get started with Actions

name: Run a shell script

# Controls when the workflow will run
on:
  # Triggers the workflow on push but only for the main branch
  push:
    branches: [ main ]

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  build:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - uses: actions/checkout@v2

      # Runs a single command using the runners shell
      - name: Run shell script
        run: ./your_script.sh

Enter fullscreen mode Exit fullscreen mode

If you're new to GitHub actions, GitHub has an excellent quickstart guide.

Oldest comments (0)