如何使用 windows 托管运行器在 Github 操作中读取 json 文件
How do I read a json file in a Github Action using a windows hosted runner
我有以下代码片段来读取 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"
您应该能够在 windows 跑步者上做同样的事情,方法是为每个步骤通知 shell: bash
,使用 bash
而不是默认的 shell windows(即 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"
我有以下代码片段来读取 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"
您应该能够在 windows 跑步者上做同样的事情,方法是为每个步骤通知 shell: bash
,使用 bash
而不是默认的 shell windows(即 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"