I’m trying to access the github deloyment vriables using the github rest api.
but I’m unable to get the variables value inside the worlflow. It throws an error
{
"message": "Resource not accessible by integration",
"documentation_url": "https://docs.github.com/rest/actions/variables#get-an-environment-variable",
"status": "403"
}
But when I’m trying to hit the same curl cmd in my local terminal with my personal access token, it works, It gives the expected result.
this is the main yaml file from where I’m calling the health.yml
name: CD
on:
push:
branches: [ "main" ]
workflow_dispatch:
jobs:
deploy:
uses: ./.github/workflows/deploy.yml
health-check:
uses: ./.github/workflows/health.yml
with:
DEPLOYMENT_TYPE: 'dev'
secrets: inherit
health-check-prod:
uses: ./.github/workflows/health.yml
with:
DEPLOYMENT_TYPE: 'prod'
secrets: inherit
This is the health.yml file
name: health
on:
workflow_call:
inputs:
DEPLOYMENT_TYPE:
required: true
type: string
jobs:
health:
runs-on: ubuntu-latest
steps:
- name: Test variables
run: |
curl -L
-H "Accept: application/vnd.github+json"
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}"
-H "X-GitHub-Api-Version: 2022-11-28"
https://api.github.com/repos/${{github.repository}}/environments/${{inputs.DEPLOYMENT_TYPE}}/variables/URL
Note: URL in the rest api endpoint is the variable name which I saved in deployment environment variables.