Reputation: 146
Trying to get the response from curl and use it in subsequent commands. Not sure what should be the correct syntax here.
- name: Get Token
run: |
response = $(curl https://********* -header "Accept: application/json" -header "X-Username: ${{ secrets.USER_NAME }}" -header "X-Password: ${{ secrets.PASSWORD }}")
echo "response from curl= $response"
Upvotes: 6
Views: 12126
Reputation: 1193
For this you first need to give your step an id, then set status or output using save-state and set-output commands. The syntax for setting output or state is -
- name: Save state
run: echo "{name}={value}" >> $GITHUB_STATE
- name: Set output
run: echo "{name}={value}" >> $GITHUB_OUTPUT
I am catching one value from curl response and setting as output, see this -
- name: run curl
run: |
status=$(curl -s --request POST \
--url https://x.com/api \
--header 'Token: ${{ env.TOKEN }}' \
--header 'content-type: application/json' \
--data '{"parameters": {"run_workflow_test":true, "source_branch":"${{ steps.comment-branch.outputs.head_ref }}"}
}' | jq -r '.state'); echo "status=$status" >> $GITHUB_OUTPUT
id: req
And to access the value from another place -
- name: test
run: echo "Result is ${{ steps.req.outputs.status }} "
Best wishes.
Upvotes: 0
Reputation: 127
I was able to solve this using below approach
- name: GET all workspace
run: |
curl --location --request GET 'https://api.getpostman.com/workspaces' --header 'X-API-Key: ${{ secrets.API_TOKEN }}' -o workspaces.json
- name: read workspace id
id: workspace
run: echo "::set-output name=id::$(cat workspaces.json | jq -c '.workspaces[] | select(.name == "My Workspace").id')"
- name: print workspace id
run: echo ${{ steps.workspace.outputs.id }}
- name: GET api's in workspace
run: |
curl --location --request GET "https://api.getpostman.com/apis?workspace=${{ steps.workspace.outputs.id }}" --header 'X-API-Key: ${{ secrets.API_TOKEN }}' -o apis.json
- name: Read api id in workspace
id: api
run: echo "::set-output name=id::$(cat apis.json | jq -c '.apis[] | select(.name == "testing-service").id')"
- name: Print api id
run: echo ${{ steps.api.outputs.id }}
Upvotes: 2
Reputation: 96
- name: Get Token
run: |
response = $(curl https://********* -header "Accept= application/json" -header "X-Username= ${{ secrets.USER_NAME }}" -header "X-Password= ${{ secrets.PASSWORD }}")
echo "response from curl= $response"
Upvotes: 2