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
.
To set a custom environment variable, you must define it in the workflow file. The scope of a custom environment variable is limited to the element in which it is defined. You can define environment variables that are scoped for: The entire workflow, by using env at the top level of the workflow file.
To add variables to the repository, you can define the variable in Secrets tab and use them in the yaml file. Note: You can access the variable in the build. xml as highlighted below. And, to make use of your variables as unencrypted, you can directly use them in the yml as highlighted below.
To add a secret to your repository, go to your repository's Setting > Secrets , click on Add a new secret . In the screenshot below, I added 2 env variables: REACT_APP_APIKey and REACT_APP_APISecret . Notice: All the environment variable you want to access with create-react-app need to be prefixed with REACT_APP .
On GitHub.com, navigate to the main page of the repository. Under your repository name, click Settings. Under the Repository Name heading, type the new name of your repository. Click Rename.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With