
GitHub Actions can be used to do something whenever something happens in one of your GitHub repositories. If you are not familiar with GitHub Actions, check out my article Getting Started with GitHub Actions.
This also assumes you are familiar with Output. If not, check out my article GitHub Actions - Getting Started with Output.
Here is an example of how you can create store the output of a curl command in GITHUB_OUTPUT and then use the output in another task in the job. In this example, the curl command should return "200" and then the "echo response" task should echo 200.
name: GitHub Action (POC)
run-name: ${{ github.workflow }} run by ${{ github.actor }}
on:
workflow_dispatch:
jobs:
poc:
runs-on: ubuntu-latest
steps:
- name: Checking out the repository code
uses: actions/checkout@v4
- name: curl https://www.example.com/
id: code
run: response=$(curl --silent --output /dev/null --write-out "%{http_code}" https://www.example.com/); echo "response=$response" >> $GITHUB_OUTPUT
- name: echo response
run: echo ${{ steps.code.outputs.response }}
More realistically, you probably are going to be getting the response code from a GET request in job1 and then only execute job2 if the response code is 200 OK, like this.
name: GitHub Action (POC)
run-name: ${{ github.workflow }} run by ${{ github.actor }}
on:
workflow_dispatch:
jobs:
job1:
runs-on: ubuntu-latest
steps:
- name: Checking out the repository code
uses: actions/checkout@v4
- name: get http://www.example.com/ response code
id: code
run: response=$(curl --silent --output /dev/null --write-out "%{http_code}" http://www.example.com/); echo "response=$response" >> $GITHUB_OUTPUT
- name: echo response
run: echo ${{ steps.code.outputs.response }}
outputs:
curl_response: ${{ steps.code.outputs.response }}
job2:
runs-on: ubuntu-latest
needs: job1
if: needs.job1.outputs.curl_response == 200
steps:
- name: Checking out the repository code
uses: actions/checkout@v4
In this example, the response code in job1 was 200 OK.
Since job1 response code was 200 OK and job2 has "needs: job1" and "if: needs.job1.outputs.curl_response == 200" this evaluated to true thus job2 was also run.
Did you find this article helpful?
If so, consider buying me a coffee over at