Well, environment secrets are specific to an environment in Github Actions which allow you to run different configurations for jobs in a single repository, e.g. to deploy to staging first and later to production.

Repository secrets are specific to a single repository (and all environments used in there), while organisation secrets are specific to an entire organisation and all repositories under it.

You can use environment secrets if you have secrets which are specific to an environment.

If you are unsure, you could also start with repository secrets for everything. If you later introduce different environments which require different secrets, you can move the repository secrets to the specific environments. Due to the inheritance chain, this should be transparent to the jobs.

Answer from Holger Just on Stack Overflow
Top answer
1 of 3
144

Well, environment secrets are specific to an environment in Github Actions which allow you to run different configurations for jobs in a single repository, e.g. to deploy to staging first and later to production.

Repository secrets are specific to a single repository (and all environments used in there), while organisation secrets are specific to an entire organisation and all repositories under it.

You can use environment secrets if you have secrets which are specific to an environment.

If you are unsure, you could also start with repository secrets for everything. If you later introduce different environments which require different secrets, you can move the repository secrets to the specific environments. Due to the inheritance chain, this should be transparent to the jobs.

2 of 3
18

To add to Holger Just's answer with an example workflow. The GitHub docs show an example when using the jobs.<job_id>.environment option in a workflow, but I think this is a more appropriate example.

name: Some task

on:
  push:
    branches:
      - main

jobs:
  prod-task:
    runs-on: ubuntu-latest
    environment: production
    steps:
      # uses production enviroment secrets over repository secrets
      - name: Run node build process
        run: "NODE_ENV=${{ env.NODE_ENV }} npm run build"
  dev-task:
    runs-on: ubuntu-latest
    environment: development
    steps:
      # uses development enviroment secrets over repository secrets
      - name: Run node build process
        run: "NODE_ENV=${{ env.NODE_ENV }} npm run build"
  task:
    runs-on: ubuntu-latest
    steps:
      # uses repository secrets as no environment is defined
      - name: Run node build process
        run: "NODE_ENV=${{ env.NODE_ENV }} npm run build"

Note: In the example above you can see the script accessing the environment variables via the env context using expressions.

So the idea is that when an environment is specified for a job, any secret used within that job, will use any environment-specific secret before using the repository secret.

To set an environment secret, navigate to the repo settings under the Environments section (i.e. https://github.com/<owner>/<repo>/settings/environments). Create or select an environment. Then add any secrets you need, see screenshot below. Make sure to provide the secret across all required environments which are to access it, otherwise the value will be inherited from parent env scope or possibly return ''.

🌐
Stepsecurity
stepsecurity.io › blog › github-actions-secrets-management-best-practices
8 GitHub Actions Secrets Management Best Practices to Follow - StepSecurity
GitHub Actions secrets are variables that enable you to store sensitive information in your repositories. These can be admin access keys, credentials, or organization secrets- all sensitive data that needs to be fully secured.
Discussions

In a github repository settings, what is difference between environments vs secrets - Stack Overflow
In a GitHub repository setting, there is an "Environments" tab and a "Secrets" tab. What is the difference between these 2 tabs? More on stackoverflow.com
🌐 stackoverflow.com
vars and secrets from environment is not being populated in actions
I have tried setting up a GitHub actions workflow in a private repository in an organization that I have admin access to. It should deploy one of our applications, and based on which branch you are pushing to it should deploy to either staging or produciton. I tried using the environment secrets and variables... More on github.com
🌐 github.com
1
10
March 9, 2023
Now v18.0.0 environment variables vs secrets
I'm wondering what happens to Now Secrets now that Environment variables feature is available. Do we need to migrate our secrets to environment variables? Are secrets deprecated or will they be dep... More on github.com
🌐 github.com
2
2
April 14, 2020
secret variables in GitHub actions - more than 100 env vars
Those secrets and variables are not meant to be used for the application configuration, but for CICD. For secrets you should use secrets managers like keyvault, hashicorp vault, infisical or sealed secrets, SOPS. Configuration can be stored in the repository in the same or in another repository depending on your deployment strategy so the changes can be reviewed and versioned. More on reddit.com
🌐 r/devops
24
36
October 29, 2024
🌐
Medium
medium.com › @george_bakas › mastering-github-actions-environment-variables-and-secrets-management-3daac384477b
Mastering GitHub Actions: Environment Variables and Secrets Management | by George Bakas | Medium
July 5, 2024 - For repository-specific configurations, use repository-level secrets to tailor workflows to the unique needs of each project. Additionally, you can use GitHub Actions Environment Files to create environment-specific variables, ensuring that each workflow runs under the appropriate conditions.
🌐
Earthly
earthly.dev › blog › github-actions-environment-variables-and-secrets
Working with GitHub Actions Environment Variables and Secrets - Earthly Blog
July 11, 2023 - While environment variables are simple dynamic values that are plugged in at runtime, secrets are more secure and are encrypted at rest. They’re usually managed by dedicated tools known as secrets managers to help create and view secrets while ...
🌐
GitHub
github.com › orgs › community › discussions › 52497
need help with variables and secrets · community · Discussion #52497
To create a temporary secret, you can use the set-env command to set an environment variable with the value of the secret. For example, suppose you want to create a temporary secret named MY_SECRET with the value my-secret-value. You can do it like this: ... name: Set temporary secret run: | echo "::set-env name=MY_SECRET::my-secret-value" Once the workflow finishes, the temporary secret will no longer be available.
Find elsewhere
🌐
AWS
docs.aws.amazon.com › aws secrets manager › user guide › get secrets from aws secrets manager › use aws secrets manager secrets in github jobs
Use AWS Secrets Manager secrets in GitHub jobs - AWS Secrets Manager
Follow the guidance in Security hardening for GitHub Actions · to help prevent secrets in your environment from being misused. You can set the entire string in the secret value as the environment variable value, or if the string is JSON, you can parse the JSON to set individual environment ...
🌐
Kubernetes
kubernetes.io › docs › concepts › configuration › secret
Secrets | Kubernetes
1 month ago - Secrets can be mounted as data volumes or exposed as environment variables to be used by a container in a Pod. Secrets can also be used by other parts of the system, without being directly exposed to the Pod.
🌐
GitLab
docs.gitlab.com › ci › variables
CI/CD variables | GitLab Docs
Variables saved in the .gitlab-ci.yml file are visible to all users with access to the repository, and should store only non-sensitive project configuration. For example, the URL of a database saved in a DATABASE_URL variable. Sensitive variables containing values like secrets or keys should ...
🌐
Graphite
graphite.com › guides › github-actions-variables
GitHub Actions variables
This method leverages the $GITHUB_ENV file to append environment variables, which are then accessible in later steps within the same job. When using environment variables to manage sensitive information, such as credentials or API keys, it’s crucial to use secrets rather than plain environment variables.
🌐
KodeKloud Notes
notes.kodekloud.com › docs › GitHub-Actions-Certification › Continuous-Deployment-with-GitHub-Actions › Understand-Github-Environments › page
Understand Github Environments - KodeKloud
In modern software development, ... by unique credentials or API keys. In this guide, you’ll learn how GitHub Actions environments help you: Securely store environment-specific secrets and variables...
🌐
MakerX
blog.makerx.com.au › leveraging-github-actions-environment-secrets-and-variables
Leveraging GitHub Actions Environment Secrets and Variables in Your Deployment Workflows
April 19, 2023 - While using GitHub Actions Environments can streamline deployment workflows, the logical way of handling secrets and variables can be more complex than desired.
🌐
Qovery
qovery.com › blog › github variables and nx reusable workflows
GitHub Variables and Nx Reusable Workflows
September 26, 2025 - Secrets are for sensitive data and cannot be shared with reusable workflows · Variables are non-sensitive data and are shared to reusable workflows through the keyword vars
🌐
GitHub
docs.github.com › en › actions › how-tos › write-workflows › choose-what-workflows-do › use-secrets
Using secrets in GitHub Actions - GitHub Docs
Secrets cannot be directly referenced in if: conditionals. Instead, consider setting secrets as job-level environment variables, then referencing the environment variables to conditionally run steps in the job.
🌐
GitHub
docs.github.com › en › actions › deployment › targeting-different-environments › using-environments-for-deployment
Managing environments for deployment - GitHub Docs
June 8, 2023 - Click Add secret. Optionally, add environment variables. These variables are only available to workflow jobs that use the environment, and are only accessible using the vars context.
🌐
LinkedIn
linkedin.com › all › devops
What are the benefits and drawbacks of using GitHub Actions secrets vs. third-party secret management tools?
January 25, 2024 - GitHub Actions secrets are encrypted environment variables that you can create and use in your repository settings or organization settings. They are only accessible to GitHub Actions and are not displayed in plain text in any log output or ...