GitLab · Opend practice case · Updated
Can a faster pipeline still deploy the right commit?
A monorepo builds an API in four minutes and a UI in ten. API tests take six minutes and UI tests take two. Both test suites currently wait for the entire build stage. Design the fastest safe deployment assuming two available runners.
Short answerSchedule each test as soon as its own build succeeds. Deploy after both required test jobs pass, then serialize access to the target environment across pipelines.
- API branch
Build from minute 0 to 4. Test from minute 4 to 10.
- UI branch
Build from minute 0 to 10. Test from minute 10 to 12.
- Release gate
Both branches are green at minute 12. Deploy the tested artifact for that commit.
Compute the critical path before adding runners
With a stage barrier, both builds finish at minute ten. The longest test then takes another six minutes. With explicit dependencies, the longest path instead takes twelve minutes. The API test occupies the runner freed by the API build. The UI build keeps its original runner. GitLab supports expressing these dependencies with needs. The timing calculation assumes no queue delay and excludes deployment time.
GitLab job dependencies with needs ↗Carry artifact identity through the graph
Tests should consume the artifact produced by their declared upstream commit. A shared mutable tag such as latest can point at a newer build by the time a test starts. Pass the digest or immutable artifact reference downstream. When an upstream test fails, block deployment and keep the failed run inspectable. A retry can rerun the failed test against the same artifact without rebuilding everything.
Handle two pipelines finishing out of order
Suppose commit B finishes while older commit A waits for a flaky test. A resource group serializes deployment to one environment. Mutual exclusion alone still permits A to deploy after B. Pick an ordering policy and add an environment check that rejects an obsolete candidate, while leaving an explicit rollback path. GitLab documents different resource-group processing modes and their requirements.
GitLab resource groups and process modes ↗| Schedule | API tests finish | Both branches ready |
|---|---|---|
| Build-stage barrier · 2 runners | 16 | 16 |
| Dependency graph · 2 runners | 10 | 12 |
| Same work · 1 runner | Order dependent | 22 |
Try the follow-upShould the deployment run at minute ten if the API tests have already passed?
Only if the deployable unit is genuinely independent of the UI and has its own release contract. In this exercise one release contains both artifacts. Removing the dependency saves time by changing what green means. Splitting releases requires a compatibility strategy and a way to roll each part back.