You can use the preinstalled gh
tool to set a repository variable from inside a workflow.
run: gh variable set VARIABLE_NAME --body "$VARIABLE_VALUE"
env:
GH_TOKEN: ${{ secrets.MY_PAT }}
This requires gh
to have write access to repository variables. This access is configured through the GH_TOKEN
environment variable.
Your workflow has access to the github.token
variable by default. However, this token does not have the required permissions.
Create a new Personal Access Token on your account and give it write access.
Store this token in your repository’s secrets, and pass it into the action that runs gh
.
If the token doesn’t have the right access, you’ll see an error like failed to set variable "VARIABLE_NAME": HTTP 403: Resource not accessible by integration
in your action’s logs.