Three pushes in a row: what should your Salesforce CI do with the stale ones?
Salesforce runs one deployment per org at a time, and a deployment with tests can take a long time. So what should your CI do when new commits arrive while an older one is still deploying? Most pipelines have no answer, and run every job in order. This post lays out the options and the one condition that decides which are safe.
The scenario
You have a CI job that validates or deploys on every push to a branch. A deployment takes 25 minutes.
- 0:00 Push 1 arrives and starts running.
- 0:10 Push 2 arrives and waits.
- 0:15 Push 3 arrives and waits behind push 2.
Run in order, push 3 is live at about 1:15, an hour after you pushed it. If push 3 contains everything from pushes 1 and 2, the first two runs were wasted time.
Three policies
| Policy | What happens | Good for |
|---|---|---|
| Run every job | 1, then 2, then 3. Nothing is skipped. | Production deployments, where each merge should have its own run and its own history. |
| Skip stale waiting jobs | Push 2 is dropped. Push 1 finishes, then push 3 runs. | Busy CI orgs where you don't want to interrupt a running job but don't need the middle one. |
| Latest wins, right away | Push 1 is cancelled and push 2 dropped. Push 3 starts at once. | Validations on pull request or integration branches, where only the newest commit matters. |
The catch: does each job deploy the whole branch?
Skipping a job is only safe if the jobs that remain still deploy what the skipped one would have.
- State-based jobs compare the whole branch as it is when the job runs against the org, and deploy the differences. Skipping push 2 is safe, because push 3's run includes push 2's changes.
- Delta-style jobs deploy only the files changed in that one push. Skipping push 2 would silently drop its changes unless the tool bundles them into the next run.
Before turning on any skipping, find out which kind your tool runs. Diffbridge compares the branch as it is when a job runs, so a commit's sha is only a label, and a skipped push can't leave the org in an older state.
Cancelling a running deployment
Cancelling asks Salesforce to stop the deployment. It is a request, not an instant stop:
- A small deployment can finish before the cancel arrives. In our own testing a superseded job still showed as succeeded for that reason.
- If you build this yourself with GitHub Actions,
concurrencywithcancel-in-progress: truestops the workflow run, but it doesn't by itself cancel a deployment that was already submitted to Salesforce. Your script has to send the cancel and wait for Salesforce to confirm before the next deployment starts.
Rules worth having whatever policy you pick
- Limit superseding to the same source. A newer push to your branch should replace your older ones, not a colleague's unrelated deployment to the same org.
- Treat validations and deployments separately. A newer validation should never replace a waiting deployment, or the other way round.
- Never supersede a rollback.
- Keep an escape hatch. An urgent fix shouldn't wait behind a long test run, so you need a way to move one job to the front and cancel the one running.
A reasonable default
Use Latest wins for validations, where only the newest commit matters, and Run every job for production deployments, where a record of each run is part of the point.
How Diffbridge does it
Every connected org has its own lane on the Deploy queue page, with a policy you set per org and can override per CI job: run every job, skip stale waiting jobs, or latest wins right away. Superseding can be limited to the same source, and applied to validations, deployments or both. Run now moves a waiting job to the front and cancels the running one. See the manual page on the deploy queue for the details.
I build Diffbridge, a Salesforce deployment tool, and this post first appeared on its blog. The advice above applies to any pipeline. If your tool handles stale pushes differently, tell me in the comments and I'll add it.