- Renaming jobs for clarity
- Introducing a dedicated Docker stage
- Controlling execution order with the
needskeyword
1. Original Workflow
Here’s the starting pipeline, which builds ASCII art, runs tests, and deploys:2. Renaming Jobs and Cleaning Up
Rename jobs for readability and remove the unnecessarysleep command:
3. Introducing a Docker Stage
Add a new docker stage with three placeholder jobs:When jobs share the same stage, GitLab CI/CD executes them in parallel. This may cause
docker_push to run before docker_build, or allow failures in docker_testing without halting docker_push.4. Docker Jobs Overview
5. Sequencing with needs
Use the needs keyword to enforce a DAG of dependencies and ensure correct ordering:
build → test → docker_build → docker_testing → docker_push.
If
docker_testing fails, docker_push is automatically skipped.
Console output for docker_testing:
6. Ignoring Stage Order
You can also launch jobs as soon as their dependencies complete, even if they’re in later stages. For example:7. Conclusion
Using theneeds keyword allows you to:
- Sequence jobs within the same stage
- Override default stage ordering for earlier execution
- Visualize your pipeline as a clear DAG