github-actions - 如何使用 Windows 托管运行器在 Github Action 中读取 json 文件

我有以下代码片段来读取 linux 托管运行器中的 json 文件。我如何使用 Windows 做同样的事情?

- id: getParams
      run: |
        content=`cat ./server.main.params.json`
        # the following lines are only required for multi line json
        content="${content//'%'/'%25'}"
        content="${content//$'\n'/'%0A'}"
        content="${content//$'\r'/'%0D'}"
        # end of optional handling for multi line json
        echo "::set-output name=packageJson::$content"
    
    #testing output from the previous command
    - name: echo ServerName
      run: echo "${{fromJson(steps.getParams.outputs.packageJson).parameters.ServerName.value}}.suffix"

回答1

您应该能够在 Windows 运行器上执行相同的操作,方法是通知每个步骤的 shell: bash,使用 bash 而不是 windows 的默认 shell(即 powershell)。

- id: getParams
   shell: bash
   run: |
      content=`cat ./server.main.params.json`
      # the following lines are only required for multi line json
      content="${content//'%'/'%25'}"
      content="${content//$'\n'/'%0A'}"
      content="${content//$'\r'/'%0D'}"
      # end of optional handling for multi line json
      echo "::set-output name=packageJson::$content"
    
    #testing output from the previous command
    - name: echo ServerName
      shell: bash
      run: echo "${{fromJson(steps.getParams.outputs.packageJson).parameters.ServerName.value}}.suffix"

相似文章

最新文章