GitHub Actions: Secrets
A secret is a private value stored in GitHub, like a password or a key. A workflow can use it without showing it in the file or in the logs.
Create the secret
Open repo Settings, then Secrets and variables, then Actions. Add a new repository secret named DEMO_GREETING, with a harmless greeting as its value.
Name: DEMO_GREETING
Value: Hello from the demo secretUse the secret in a step
Read it through the secrets context. Do not type the value in the file.
- run: 'echo "Greeting: ${{ secrets.DEMO_GREETING }}"'What the log shows
GitHub replaces the secret value with stars in the log.
Greeting: ***Example
name: Secrets demo
on:
push:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: '24'
- run: npm test
- run: 'echo "Greeting: ${{ secrets.DEMO_GREETING }}"'Key points
- Use a secret for any value that must stay private.
- Create a secret in repo Settings, then Secrets and variables, then Actions.
- Give the secret a clear name in capital letters, like DEMO_GREETING.
- A workflow reads a secret with ${{ secrets.NAME }}.
- GitHub masks a secret value in logs, so it shows as ***.
- A secret is never printed in full, even by mistake in a log.
In this example, the workflow checks out the code and sets up Node 24. It runs the tests first. The last step prints the DEMO_GREETING secret. The secret was created in repo Settings under Secrets and variables, then Actions, with a harmless greeting as its value. GitHub masks the value in the log, so it shows as ***.
Note
A secret value is not visible after it is saved. Keep a copy somewhere safe if you need it again.
Try it Yourself
Edit the code, then press Run.
Running is simulated · Rust Playground
Exercise
Where does a repository secret live, and how does a workflow read it?