GitHub Actions 因从 JsonReader 错误读取 JToken 而失败
Posted
技术标签:
【中文标题】GitHub Actions 因从 JsonReader 错误读取 JToken 而失败【英文标题】:GitHub Actions fails with reading JToken from JsonReader error 【发布时间】:2021-11-15 11:42:27 【问题描述】:我正在尝试遵循How to use GitHub Actions build matrix to deploy artifacts to multiple servers 教程。我已经完成了一半的教程,但是在构建应用程序时出现以下错误。
Error when evaluating 'strategy' for job 'prepare-release-on-servers'. (Line: 53, Col: 17): Error reading JToken from JsonReader. Path '', line 0, position 0.,(Line: 53, Col: 17): Unexpected value ''
我已经检查了 validation 的 JSON 文件,并且无数次地检查了部署文件。
这是 deploy-application.yml 文件。
name: Deploy Application
on:
push:
branches:
- main
jobs:
create-deployment-artifacts:
name: Create deployment artifacts
runs-on: ubuntu-latest
outputs:
deployment-matrix: $ steps.export-deployment-matrix.outputs.deployment-matrix
steps:
- uses: actions/checkout@v2
- name: Compile CSS and javascript
run: |
npm install
npm run prod
- name: Configure php 8.0
uses: shivammathur/setup-php@v2
with:
php-version: 8.0
extensions: mbstring, ctype, fileinfo, openssl, PDO, bcmath, json, tokenizer, xml
- name: composer install
run: |
composer install --no-dev --no-interaction --prefer-dist
- name: Create deployment artifact
env:
GITHUB_SHA: $ github.sha
run: tar -czf "$GITHUB_SHA".tar.gz --exclude=*.git --exclude=node_modules --exclude=tests *
- name: Store artifact for distribution
uses: actions/upload-artifact@v2
with:
name: app-build
path: $ github.sha .tar.gz
- name: Export deployment matrix
id: export-deployment-matrix
run: |
JSON="$(cat ./deployment-config.json)"
JSON="$JSON//'%'/'%25'"
JSON="$JSON//$'\n'/'%0A'"
JSON="$JSON//$'\r'/'%0D'"
echo "::set-output name=deployment-matrix::$(echo $JSON)"
prepare-release-on-servers:
name: "$ matrix.server.name : Prepare release"
runs-on: ubuntu-latest
needs: create-deployment-artifacts
strategy:
matrix:
server: $ fromJson(needs.create-deployment-artifacts.outputs.deployment-matrix)
steps:
- uses: actions/download-artifact@v2
with:
name: app-build
这是 JSON 文件。
["name":"server-1","ip":"216.656.30.240","username":"root","password":"sdddssafilgwzxcxvgvggfdassa","port":"22","beforeHooks":"","afterHooks": "","path": "/var/www/html" ]
我在这里找不到问题。你能帮忙的话,我会很高兴。提前致谢。
【问题讨论】:
【参考方案1】:当set-output
应该被fromJSON
加载时,所有双引号"
应该被替换(转义)到$JSON
字符串中的\"
。见this post。
【讨论】:
以上是关于GitHub Actions 因从 JsonReader 错误读取 JToken 而失败的主要内容,如果未能解决你的问题,请参考以下文章
是否可以在 GitHub Actions 中的 Actions 之间保留 WORKDIR?
使用GitHub Actions自动构建DockerHub镜像