# Turn on deploy on push

Make an app built from a repository deploy every push to its branch, or stop it from doing so.

With deploy on push, the pushed commit is built and rolled out as the person who pushed, with the
trigger `push` in the deployment history. Merging a pull request into the branch counts as a push.
Every push deploys, whichever files it changed: a push that only touches files outside the app's
root directory still rolls out. A new app connected to a repository has it on unless you turn it
off (**Deploy on push** in **Create app**, or `deployOnPush: false`). While it is off, the app's
**Deployments** tab says that pushes to the branch do not deploy it.

## Prerequisites

- An app connected to a repository: built from it, or running a compose file read from it.
- Permission for `deploy:UpdateApp` on the app.
- For each push to deploy, the person who pushed needs `deploy:DeployApp` on the app.
- In the console, also `deploy:DescribeApp` to open the app's page (without it the page is not
  found).

## Turn it on or off

**Console**
1. Open the app's **Runtime** tab.
2. Under **Deploy on push**, select or clear **Deploy every push to** _branch_. The change is
   saved at once; there is no Save button. Without `deploy:UpdateApp` the check box is unavailable
   and the panel says "Changing this needs permission to update the app."

**CLI**
```sh
dcloud deploy apps update app-id --deploy-on-push
```

`--no-deploy-on-push` turns it off. Replace app-id with the app's id.

**API**
```http
PATCH /deploy/api/apps/3f1c2b4a-5d6e-4f70-8a91-b2c3d4e5f601
{ "deployOnPush": true }
```

**Terraform**
```hcl
resource "dcloud_app" "web" {
  name           = "my-app"
  builder           = "dockerfile"
  git_repository_id = dcloud_git_repository.api.id
  deploy_on_push    = true
}
```

## Result

The change applies from the next push. A push by someone without `deploy:DeployApp` is not
deployed, and the app's activity says so, for example: _Push `a1b2c3d` to main by jane-doe did not
deploy: jane-doe may not deploy this app (deploy:DeployApp)_. A push that does deploy is noted
too: _Push `a1b2c3d` to main by jane-doe: deploying it as generation 8_.

## Related

- [Create an app from a repository](create-an-app-from-a-repository.md)
- [Deploy an app](deploy-an-app.md)
- `deploy.apps.update` · `dcloud deploy apps update` · `dcloud_app`
