How would you get the repository name (not the user or organization) as an environment variable in GitHub Actions?
I found github.repository but that contains the owner as the first part like so: owner/repo.
8
votes
2 Answers
11
votes
I think the syntax you're looking for is actually github.event.repository.name
@Samira's toJson(github) tip was super useful. It took me a send look to notice the repository property was indented a bit further in, under `event.
You can use the value directly, or assign it at the top level with:
env:
REPO_NAME: ${{ github.event.repository.name }}
10
votes
Try github.event.repository.name
- run: echo ::set-env name=REPO_NAME::${{ github.event.repository.name }}
Documentation aside, i'd really recommend dumping contexts (maybe in some test repo) just to get familiar with them, as there is lot of data which might or might not be useful when writing non-trivial workflows.
- name: Dump github context
run: echo "$GITHUB_CONTEXT"
shell: bash
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
Be aware that parts of github context changes depends which event triggered workflow, so it might be a good idea to double check if data you want to use is available for all events used in workflow.