Is there a way i can specify the github action workflow to use powershell 7 instead of default powershell 5?

huangapple go评论83阅读模式
英文:

Is there a way i can specify the github action workflow to use powershell 7 instead of default powershell 5?

问题

我有一个工作流程,将在本地运行器上运行一个PowerShell脚本,我已经尝试与ChatGPT争论,但它无法给我一个正确的答案,告诉我如何指定我要使用PowerShell 7。这是因为PowerShell脚本中使用的一个模块不支持较早版本的PowerShell。

这是工作流YAML文件目前的样子:

name: PowerShell脚本
on:
  push:
    branches:
      - master

jobs:
  myJob:
    name: PS - 更新列表
    runs-on: self-hosted

    steps:
      - name: 检出存储库代码
        uses: actions/checkout@v3
        with:
          fetch-depth: 1

      - name: 运行PowerShell脚本
        shell: pwsh7
        env:
          Creds: ${{ secrets.Creds }}
        run: |
                    ./Something.ps1

错误:

Is there a way i can specify the github action workflow to use powershell 7 instead of default powershell 5?

英文:

I have a workflow that is going to run a powershell script on a local runner, i have tried arguing with chatgpt but it cannot give me a correct answer to how i can spesify that i want to use powershell 7. This is needed because one of the modules used in the powershell script is not supported in earlier versions of powershell.

This is what the workflow yaml file is currently looking like:

name: Powershell script
on:
  push:
    branches:
      - master

jobs:
  myJob:
    name: PS - Update list
    runs-on: self-hosted

    steps:
      - name: Check out repository code
        uses: actions/checkout@v3
        with:
          fetch-depth: 1
      
      - name: Run PowerShell script
        shell: pwsh7
        env:
          Creds: ${{ secrets.Creds }}
        run: | 
          ./Something.ps1

Error:

Is there a way i can specify the github action workflow to use powershell 7 instead of default powershell 5?

答案1

得分: 1

感谢大家的评论!
正如Mathias在评论中写道,我必须使用'shell: pwsh',这将始终将PowerShell 7作为默认选项。如果您要使用早期版本,如PowerShell 5,则需要更改为其他选项,我相信。

英文:

Thanks for everyones comments!
As Mathias wrote in a comment i had to use 'shell: pwsh' instead this always uses powershell 7 as default. If you're gonna use an earlier version like powershell 5 then you need to change this to something else i belive.

huangapple
  • 本文由 发表于 2023年7月6日 17:04:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/76627184.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定