【问题标题】:How to save command result in GitHub如何在 GitHub 中保存命令结果
【发布时间】:2022-11-30 15:53:17
【问题描述】:

我希望能够保存我运行的任何命令的结果,以便我可以在我的 YAML 文件中决定下一步要做什么

这是一个与我想要的类似的非工作示例的示例

- name: Run script
        shell: powershell
        run: |
          status = script\\outputZero.ps1
          if: status == 0
              echo "output was 0" 

我也试过这样做

- name: Run script
        shell: powershell
        run: |
          if: script\\outputZero.ps1
              echo "output was 0" 

但它给了我错误术语 “if:”未被识别为 cmdlet、函数、脚本文件或可运行程序的名称。

【问题讨论】:

    标签: powershell github yaml github-actions


    【解决方案1】:

    来自Building and testing PowerShell 的示例,而是使用shell: pwsh(可能是powershell 的同义词)

    参见例如:

      lint-with-PSScriptAnalyzer:
        name: Install and run PSScriptAnalyzer
        runs-on: ubuntu-latest
        steps:
          - uses: actions/checkout@v3
          - name: Install PSScriptAnalyzer module
            shell: pwsh
            run: |
              Set-PSRepository PSGallery -InstallationPolicy Trusted
              Install-Module PSScriptAnalyzer -ErrorAction Stop
          - name: Lint with PSScriptAnalyzer
            shell: pwsh
            run: |
              Invoke-ScriptAnalyzer -Path *.ps1 -Recurse -Outvariable issues
              $errors   = $issues.Where({$_.Severity -eq 'Error'})
              $warnings = $issues.Where({$_.Severity -eq 'Warning'})
              if ($errors) {
                  Write-Error "There were $($errors.Count) errors and $($warnings.Count) warnings total." -ErrorAction Stop
              } else {
                  Write-Output "There were $($errors.Count) errors and $($warnings.Count) warnings total."
              }
    

    请注意if 之后缺少:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-11
      • 2011-12-29
      • 2012-04-21
      • 1970-01-01
      • 1970-01-01
      • 2011-07-16
      • 2020-02-13
      • 2022-11-10
      相关资源
      最近更新 更多