Environments, deploys and approvals
An environment is a place a project's runs deploy to, such as staging or production.
Each environment has protection rules. A run that names an environment must pass them before
it starts: some are checked when the run is created, others make it wait for approval or a
timer. Every run that deploys is kept as a deployment in the environment's history.
Set one up
Open the project's Environments page (in the Automation section) and choose New environment.
- Name: lowercase letters, digits and dashes, at most 63 characters, unique in the project. Run specs, templates and flows name the environment by it.
- Description and URL: optional. The URL is where the environment can be reached; it shows on its deployments.
A project has at most 50 environments. Adding, changing and deleting them needs the
environment:write permission, which owners, admins and maintainers hold. Without it the page
shows the rules read-only. Deleting an environment deletes its variables, secrets and
deployment history.


Protection rules
| Rule (console) | Default | What it does |
|---|---|---|
| Require approval | off | A run waits until enough reviewers approve it. |
| Required reviewers | none | Up to 10 roles or people. Without any, everyone with "Approve runs that deploy to environments" in the project may approve. |
| Approvals needed | 1 | 1 to 10. |
| Prevent self-review | on | Whoever started the run can't approve it. |
| Approval timeout (days) | 7 | A run nobody decides on within this many days is rejected. 1 to 30. |
| Wait timer (minutes) | 0 | Minutes to wait after approval, or before the start when no approval is needed. Up to 43200 (30 days). |
| Allowed branches and tags | all | Up to 50 patterns, such as main, release/* or v*. A line starting with ! excludes. |
| Allow runs without a Git context | on | Manual runs and schedules have no branch or tag. Untick it to let only Git-started runs deploy. |
A run is refused when it is created if:
- the project has no environment of that name;
- it has no Git context and the environment doesn't allow that;
- the environment has allowed branches and tags and the run's ref matches none. A pull request's run matches none, so it can only deploy where all refs are allowed;
- it is a run of a pull request from a fork, and the environment requires approval or has a wait timer.
Every retry and re-run checks the rules again, so a rule changed in the meantime applies.
In the run spec
image: alpine:3.20
command: [./deploy.sh]
environment:
name: staging
url: https://staging.example.com # optional: this deployment's address
environment works wherever a run spec does: a plain run, a template, a flow step or a run
file. On the command line, forge run --environment staging … sets the name. On the New run
form it is under Advanced.
A deploy that must not overlap with itself can also use a concurrency group, so only one run of the group is active at a time:
concurrency:
group: deploy-production
Approving and rejecting
A run to a protected environment starts in the state waiting for approval. While it waits it holds no queue slot and no runner.
- With Require approval, it waits for the number of approvals needed. One rejection ends the run as rejected, whatever approvals came before. A run nobody decides on in time is rejected too.
- Once approved (or at once, without approval), it waits for the wait timer. It can be cancelled meanwhile.
- It then joins the queue. First Forge checks that whoever started it still may create runs and use what it uses, such as secrets. If not, the run is rejected.
Who may decide: a listed reviewer (a person, or someone with a listed role in the project) who
also holds environment:approve. Without listed reviewers, anyone with environment:approve in
the project. Owners, admins and maintainers hold it. See
members and roles.
Where to decide
-
Console: the run page shows what the run waits for and the decisions so far, with Approve and Reject and an optional comment. The comment is shown on the run and in the audit log.
-
Approvals pages: a project's lists its runs that wait to deploy, oldest first. The organization's lists those of every project you can see, with a switch for Only runs I may decide, and its menu item shows how many wait for you.
-
Command line:
forge approve -m "Checked the migration" RUN forge reject -m "Not during the sale" RUN
Forge sends no email about approvals. Use the Approvals pages, or subscribe a
webhook to run.approval_requested and run.rejected.
In a flow
A flow step's run waits the same way. One decision covers every run of the flow run that waits for the same environment, and later steps of that flow run to the same environment start without asking again. A re-run of the flow is a new flow run and asks again. An approval step asks for a decision without deploying anything. See flows.
A run file or flow file in a repository may only name the environments its Git trigger allows, since anyone who can push can edit the file. See Git.
Variables and secrets per environment
An environment has its own variables and secrets, on its page. A run that deploys there gets
them; other runs don't. An environment's secret comes before the project's of the same name, so
DB_PASSWORD can be the project's for every run and the environment's for production. See
secrets and variables.
Deployment history
Every run that names an environment records a deployment, and each retry is one of its own. A deployment's state follows the run's. It keeps a copy of what was deployed: the run's number, its repository, ref and commit, who started it and who approved it, and its URL. So it stays after the run itself is gone.
- The current deployment is the last one that succeeded.
- An environment keeps its last 500 deployments, and always the current one.
- The environment's page shows the current deployment and the history, newest first.
For runs started from GitHub or GitLab, Forge also reports the deployment on the commit, for the environment of the same name there. On GitHub that needs the Forge app's Deployments permission.
From the command line
forge environments # list the project's environments
forge environments show production
forge environments add --require-approval --min-approvals 2 \
--reviewer role:ROLE_ID --allowed-ref main --wait-timer 15 production
forge environments set --url https://example.com production # changes only the flags given
forge environments set --reviewer none --allowed-ref none production
forge environments deployments --limit 50 production # * marks the current one
forge environments delete staging
--reviewer (user:ID or role:ID) and --allowed-ref repeat and replace the whole list;
none empties it. Other flags: --description, --prevent-self-review, --allow-manual and
--approval-timeout. Pick the project with --project or FORGE_PROJECT.
Good to know
Forge runs jobs that end with an exit code. It doesn't keep long-running services up for you; a deploy run hands your application to wherever it runs. The companion containers a run can start, such as a database for its tests, are covered in services.