Windows - run a PowerShell script

Trying to move CI from AppVeyor to Actions, which used PowerShell files for build and test.

Reviewed https://help.github.com/en/articles/workflow-syntax-for-github-actions#jobsjob_idstepsrunshell, which I found without examples.  So, stupid question - how to run a ps1 file in an Actions step?

I was also trying to figure out how to use the shell option to run a powershell script. The doc shows the following definition:

jobs.<job_id>.steps.run.shell

So I tried to make a sub-property of run (which I don’t think is valid yml, but the editor doesn’t do any validation so it’s hard to tell):

name: CI

on:
  push:
    branches:
    - master

jobs:
  build:

    runs-on: windows-2019

    steps:
    - uses: actions/checkout@v1
    - name: Run a one-line script
      run: .\MyScripts\install.ps1
        shell: powershell

Which errored with:

yaml: line 17: mapping values are not allowed in this context

I gave up and just used powershell from the cmd command instead of trying to change the shell:

name: CI

on:
  push:
    branches:
    - master

jobs:
  build:

    runs-on: windows-2019

    steps:
    - uses: actions/checkout@v1
    - name: Run a one-line script
      run: powershell .\MyScripts\install.ps1

Hopefully some examples can be added to that page to show how to actually use the shell parameter

Try:

name: CI

on:
  push:
    branches:
    - master

jobs:
  build:

    runs-on: windows-2019

    steps:
    - uses: actions/checkout@v1
    - name: Run a one-line script
      run: .\MyScripts\install.ps1
      shell: powershell

Its working for me - https://github.com/damccorm/actions-playground/pull/9 - I think this is just a docs issue

cc @rachmari 

1 Like

Hey there, thanks for pointing this out. It was indeed a documentation bug. We’ve fixed the documentation and added examples for using different shells! Let me know if there is still some clarification we can make in the documentation. 

You’ll find the updated documentation here:
https://help.github.com/en/articles/workflow-syntax-for-github-actions#jobsjob_idstepsrun

2 Likes