I am using GitHub Issue form to capture few inputs from User. Once form is submitted, I am using JSON parser to retrieve the form inputs.
When I run echo ${{ steps.parser.outputs.json }}
, I am able to view the JSON output (displayed below). However, I have 3 inputs that I would like to pass as an environment variable for next job.
My current issue is, when I run Test step, I can view JSON for $SOURCE_BRANCH
(Which matches with the output of the code, this not not what I am looking for).
I would like to pass values for each Keys as an environment variable for next action. Is there any actions in Marketplace or any easier approach to solve the issue?
My YML file:
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
JSON output from echo:
source_branch:DEV target_branch:UAT folders_double_quoted_comma_separated_within:_No response_ contact_details:_No response_
You need to extract the json values and assign each value:
- 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
1