Deploy now, redeploy and switch branches
Most of the time deployments start by themselves, from a push or from CI. Sometimes you start one yourself: you changed an environment variable, you fixed the cause of a failure, or you simply want the latest code live now. This article covers those manual moves, the Deploy now button and Redeploy, how to cancel a deployment or free a site whose deployment is stuck, and how to make a site deploy a different branch.
It is also honest about a limit that people look for: SrvYard always deploys the latest commit of the site's branch. There is no field for a commit hash and no per-deployment branch picker. The last section lists the ways to get a specific version live instead.
Before you begin
- A repository and a ready site. Deploying needs a site in the Ready state on a ready server, with a repository and a non-empty deploy script. If any of these is missing, Deploy now is disabled and a line above the history says why, for example "Connect a repository to this site before deploying." or "The deploy script is empty."
- The permission to manage deployments. Owners and admins have it. Without it the buttons are not shown.
- A deploy script you trust. Read Write and test a deploy script before your first manual deployment.
1. Deploy now
Open the site's Deployments tab.
- Deploy now. Queues a deployment straight away; there is no confirmation. The toast says "Deployment queued." and a side sheet opens with the live output of the new deployment so you can watch it.
- Source. Shows what will be deployed: the repository and the Branch. The deployment fetches the tip of that branch at the moment it starts.
- Open deployment settings. Leads to the deploy script, retention, shared paths, health checks and notifications.
If another deployment of the site is running or waiting, yours waits in line as Queued ("Waiting for the deployment before this one to finish.") and starts when the one before it ends. Two deployments of the same site never run together.
Everything else about the run is the same as for an automatic one: the same script, the same health check, and the history records Manual deployment and your name under Triggered by.
After changing an environment variable you do not need two steps: on the Environment tab, Save and deploy writes the file to the server and then starts a deployment, the same as pressing Deploy now afterwards. See Edit environment variables.
A manual deployment is also the safest way to test a change to the deploy script: save the script, press Deploy now and watch the output sheet. If it fails before the release goes live, visitors are not affected. For an in-place site the same is not true, because the code is updated where it is served.
2. Cancel a deployment
Open the row menu of a Queued or Running deployment and choose Cancel deployment. The dialog explains what happens:
- A queued deployment "will not start. The current release stays live."
- A running one has its deploy script stopped and the half-built release removed. "The current release stays live."
The deployment ends as Cancelled and the next waiting one starts. If the script was already past the switch (the release is live) cancelling is no longer possible: the deployment has ended.
3. Redeploy after a failure
After you have fixed the cause of a failure, open the failed deployment's page. Under Why it failed, press Redeploy.
- Deploy again? "Start a new deployment of the latest commit. Make sure the fix above is in place first." Press Deploy to queue it.
Note that this is not a replay of the failed commit. It is a fresh deployment of whatever is at the tip of the branch now, so a fix you pushed is included. The fix might also be on the server rather than in Git (an environment variable, a missing PHP extension): then nothing needs pushing and Redeploy is enough.
You can use Deploy now instead; the result is identical.
4. Free a site whose deployment is stuck
A deployment that has been Running for more than 30 minutes without reporting back is probably dead (for example the worker was restarted). While it is marked as running, new deployments wait behind it. Two ways out:
- Reset deployment state. In the site actions menu (the three dots at the top right of the site). It "fails the deployments that have been waiting or running for more than 30 minutes without reporting back, so a new deployment can start. A deployment that is still working is not touched." Check the server first: the script may really still be running.
The row menu of the stuck deployment also has Reset stuck deployment for that single run.
5. Deploy a different branch
The branch a site deploys is a setting of the site, not of a single deployment. To deploy another branch:
- Open Settings > General.
- Change Branch. For a repository chosen from a provider it is a list of the repository's branches; for a Custom Git URL it is a text field. Press Save.
- Press Deploy now.
- Branch. The branch every deployment fetches from now on, and the one push to deploy listens to. A zero-downtime site clones it fresh, so switching is safe; an in-place site fetches it into the existing folder and resets the files to it.
- Save. "Settings saved. Repository changes apply on the next deployment." Nothing is deployed until you start a deployment.
Switching branches back and forth on a production site is easy to forget. For a branch you want to test, create a second site on the same server with the same repository and the other branch (for example staging.example.com), and keep production on its own site.
The deploy hook's ?branch= option does not switch branches either: it only makes the request do nothing when the branch name does not match the site's branch.
6. Getting an older version live
SrvYard clones with --depth 1, so only the newest commit of the branch is fetched. To get an older version, use one of these:
- Roll back to an earlier release that is still on the server. It is instant and does not run the script. See Zero-downtime releases and rollbacks.
- Revert in Git. Revert the commit (or reset the branch) and push, then deploy. The history stays clear about what is live.
- Create a branch at the old commit, set the site to that branch and deploy.
Troubleshooting
- Deploy now is greyed out. Hover over it or read the line above the history: the site is not ready, the server is not ready, there is no repository or the deploy script is empty.
- "This deployment has already ended." You pressed Cancel just after it finished. Nothing is wrong.
- The deployment stays Queued. Another deployment of the site is running or stuck. Open it, or use Reset deployment state if it is over 30 minutes old.
- I clicked Deploy now twice and got two deployments. A manual click always queues one. (Pushes and hook requests do not pile up: a waiting deployment absorbs them.) Cancel the second one.
- The deployment used the old branch. You did not press Save in the repository settings, or the deployment started before you saved. Save, then deploy.
- "Deploys are turned off for this adopted site." An adopted site can have deployments switched off. See Adopt a site that is already on your server.
Related
- Read a deployment log and find the failing step: before you redeploy, know why it failed.
- Zero-downtime releases and rollbacks: go back instead of forward.
- Connect a repository and pick a branch: the repository and branch settings in detail.
- Deploy automatically on every push: stop starting deployments by hand.