Sub topic 3
Where environments and rules are available
This chapter assumes you can read workflow YAML, use repository settings, and know what a job's needs does. Before you design a pipeline around environments, check whether your repository's visibility and plan support the features you want. A pipeline that depends on required reviewers will not gate anything if the repository can't use them.
The availability rules
GitHub ties environment features to two things: whether the repository is public, private, or internal, and which plan owns it.
| Feature | Public repository | Private or internal repository |
|---|---|---|
| Environments and environment secrets | All plans | GitHub Pro, Team, or Enterprise |
| Deployment branch and tag restrictions | All plans | GitHub Pro, Team, or Enterprise |
| Required reviewers, wait timer, custom protection rules | All plans | GitHub Enterprise |
Required reviewers and the wait timer are the rules this tutorial focuses on. A private repository on Pro or Team can use environments, secrets, and branch restrictions, but it can't use those two rules.
Common errors
- Assuming a rule is enforced because the YAML looks right. The
environment:key is valid syntax on any plan. A job that names an environment can run with none of the protections you expect. Confirm the rule appears under the environment's settings. - Letting a workflow create the environment. If a job references an environment that doesn't exist, GitHub creates it with no protection rules. A typo such as
produtiontherefore gives you a new, unprotected environment instead of an error. Create environments in settings or through the API first. - Planning around the plan you wish you had. A private repository on Team can't require reviewers. Either move to Enterprise, make the repository public if that is appropriate, or use another control, such as protected branches on the deployment branch.
Checking your own repository
Open Settings and look for Environments in the sidebar. If it is missing, the repository's plan and visibility don't include environments. Open an existing environment and look at the Deployment protection rules section. The options you see there are the ones you can use.
Plan terms change over time, so treat this table as a snapshot and check GitHub's current documentation before you commit to a design.
Exercise
Your team has a private repository on the GitHub Team plan. You want production deploys to wait for a reviewer's approval and to run only from main. Which of these can you configure, and what could you do about the other?
Show answer
You can restrict deployments to main, because deployment branch rules are available in private repositories on Team. You can't configure required reviewers there, because that rule needs GitHub Enterprise for private or internal repositories. To get approval gating, upgrade to Enterprise. Otherwise, add other controls, such as branch protection on main that requires a pull request review before code can reach the deployment branch.