我正在使用 GitHub 问题表单来捕获用户的一些输入。提交表单后,我将使用 JSON 解析器来检索表单输入。
当我运行
echo ${{ steps.parser.outputs.json }}
时,我可以查看 JSON 输出(如下所示)。然而,我有 3 个输入,我想将它们作为下一个工作的环境变量传递。我当前的问题是,当我运行测试步骤时,我可以查看 $SOURCE_BRANCH 的 JSON(这与代码的输出匹配,这不是我想要的)。我想将每个键的值作为下一步操作的环境变量传递。 Marketplace 中是否有任何操作或任何更简单的方法来解决该问题?
YML 文件
name: JSON
on:
issues:
types: [opened]
jobs:
issue-retrieval:
runs-on: ubuntu-latest
permissions:
issues: write
contents: read
packages: read
steps:
- name: Parse Issue
id: parser
uses: issue-ops/[email protected]
with:
body: ${{ github.event.issue.body }}
- name: Output Issue JSON
id: output-issue
run: |
echo ${{ steps.parser.outputs.json }}
# Set environment variables
echo "SOURCE_BRANCH=$(echo ${{ steps.parser.outputs.json }})" >> $GITHUB_ENV
echo "TARGET_BRANCH=target_branch" >> $GITHUB_ENV
echo "FOLDERS=folders_double_quoted_comma_separated_within" >> $GITHUB_ENV
- name: Test
run: |
echo $SOURCE_BRANCH
echo $TARGET_BRANCH
echo $FOLDERS
echo 的 JSON 输出:
source_branch:DEV target_branch:UAT folders_double_quoted_comma_separated_within:_No response_ contact_details:_No response_
您需要提取 json 值并分配每个值:
- name: Output Issue JSON
id: output-issue
run: |
echo ${{ steps.parser.outputs.json }}
# Set environment variables
echo "SOURCE_BRANCH=$(echo '${{ steps.parser.outputs.json }}' | jq -r '.source_branch')" >> $GITHUB_ENV
echo "TARGET_BRANCH=$(echo '${{ steps.parser.outputs.json }}' | jq -r '.target_branch')" >> $GITHUB_ENV
echo "FOLDERS=$(echo '${{ steps.parser.outputs.json }}' | jq -r '.folders_double_quoted_comma_separated_within')" >> $GITHUB_ENV