You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Setting output for a step in a job, so a different job can use it
In the specific job element (so create-issue-comment in the example below), add the field outputs
The label for your variable is what you will use to refer to it in other jobs. In the example below, the label is issue_json
Use the ${{ }} syntax to access the result of one of the steps in this job. Inside the curly braces, use dot syntax to identify the path to the step's output
In the example below, ${{ steps.set-json.outputs.issue_json }} is looking for one of the steps in the current job with an id of set-json and expecting it to have set an outputs called issue_json
In the step with the result you need to save, have it echo the variable name you chose in your outputs (in this case, issue_json) to $GITHUB_OUTPUT, a constant that GH uses to catch output.
You have to add the id element to your steps to refer to them properly
name: Process new issueson:
issues:
types: [labeled, opened]jobs:
create-issue-comment:
runs-on: ubuntu-latest# The output variables that get createdoutputs:
issue_json: ${{ steps.set-json.outputs.issue_json }}steps:
# Parse the JSON from the issue body
- name: Parse issueid: parseuses: peter-murray/issue-forms-body-parser@v2.0.0with:
issue_id: ${{ github.event.issue.number }}separator: '###'label_marker_start: '>>'label_marker_end: '<<'# Save the parsed JSON as output
- name: Set JSONid: set-json# Use the `outputs.payload` from the `parse` step run: echo "issue_json=${{ steps.parse.outputs.payload }}" >> $GITHUB_OUTPUT# This is a new job see-output:
## Specify that this job needs the `create-issue-comment` job to run first needs: create-issue-commentruns-on: ubuntu-lateststeps:
# Access the `issue_json` by traversing the `outputs` of the job identified in `needs`
- name: Prove we got the linkrun: echo "${{ needs.create-issue-comment.outputs.issue_json }}"