GitHub Actions powershell shell not working pwsh: command not found

485 views Asked by At

I have a github actions runner running on my win10 machine, it is running in command prompt. I have a basic github actions workflow here:

name: Release New NuGet Package Test

on:
  workflow_dispatch:
    inputs:
      nugetPkgProjectName:
        description: 'Enter your NuGet Package Project Name:'
        required: true
        type: string
      incrementMinorVersion:
          description: 'Set to "true" if you want to increment minor and set patch to zero.'
          required: false
          type: string
      descriptionVar:
          description: 'What changes were made in this version?'
          required: false
          type: string

jobs:
  begin:
    runs-on: martin-laptop
    steps:
        - uses: actions/checkout@v3
          with:
            sparse-checkout: |
              Martin Nuget Work

        - name: Extract Branch and Commit
          run: |
            echo "Branch = ${{ github.ref_name }}"
            echo "Commit = ${{ github.sha }}"

        - name: Determine NuGet Package Version
          id: run-ps-script
          shell: pwsh
          run: |
            Write-Host "here is some pwsh stuff"
            Write-Host "cool env var : $env:GITHUB_ACTION_PATH/Martin Nuget Work"
            

When I trigger this workflow in github actions, it fails at the last step 'Determine NuGet Package Version' with this error:

  Run Write-Host "here is some pwsh stuff"
  Write-Host "here is some pwsh stuff"
  Write-Host "cool env var : $env:GITHUB_ACTION_PATH/Martin Nuget Work"
  Error: pwsh: command not found

This has worked fine in the past, but now on this new machine, a pwsh shell command never passes, is it an issue with my runner?

1

There are 1 answers

0
Benjamin Michaelis On
  1. Make sure martin-laptop has pwsh installed (can you type pwsh locally from your command line)
  2. Set the shell that the command is executing in to be pwsh either through defaults or on your specific step.

https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#defaultsrun

Ex:

name: Sample Workflow

on:
  push:
    branches:
      - main

jobs:
  build:
    runs-on: ubuntu-latest
    defaults:
      run:
        shell: pwsh

    steps:
      - name: Run a script with pwsh in a specific step
        shell: pwsh
        run: Write-Host "This step specifically uses pwsh as its shell."