How to Use GitLab Duo in Your DevSecOps Workflow: A Complete Guide
GitLab Duo is GitLab’s suite of AI features that live directly inside your DevSecOps workflow. In this tutorial you will learn how to use GitLab Duo to explain code, generate tests, summarize merge requests, and get AI assistance without leaving GitLab.
What Is GitLab Duo?
GitLab Duo spans the whole software lifecycle: code suggestions while you type, chat that understands your repository, merge request summaries, root cause analysis for failed pipelines, and security explanations. Because it runs inside GitLab, it has context about your project that a standalone assistant does not.
Step 1: Enable GitLab Duo
An administrator must turn on GitLab Duo for the group or project and assign seats. Check whether your GitLab version is self-managed or GitLab.com, because enablement steps differ slightly. Once enabled, look for the GitLab Duo icon in merge requests, issues, and the Web IDE.
- Confirm your license includes GitLab Duo.
- Enable it at the group level.
- Assign seats to team members.
- Verify the Duo icon appears in a project.
Step 2: Use Code Suggestions
In the Web IDE or your editor with the GitLab extension, start typing code and GitLab Duo offers completions inline. Press the accept key to keep a suggestion or keep typing to dismiss it. You can also write a comment describing what you want and let GitLab Duo generate the block below it.
Step 3: Explain and Refactor with Duo Chat
Open GitLab Duo Chat and ask it to explain a function, summarize a file, or refactor a method. Because chat can reference the current project, you can ask questions like “where is authentication handled” and get pointed at the right files. Use it to onboard onto unfamiliar codebases quickly.
Step 4: Generate Tests and Fix Pipelines
Ask GitLab Duo to write unit tests for a selected class, then review and commit them. When a pipeline fails, use the root cause analysis feature: GitLab Duo reads the job logs, identifies the likely cause, and suggests a fix. This shortens the debugging loop considerably.
- Select a class and request unit tests.
- Review generated tests for edge cases.
- Open a failed job and run root cause analysis.
- Apply the suggested fix and re-run the pipeline.
Step 5: Summarize Merge Requests
On a merge request, click the GitLab Duo summarize button to generate a plain-language description of what changed. Reviewers get context instantly instead of reconstructing intent from a diff. You can also ask chat to review the changes and flag potential problems before a human looks.
Step 6: Secure Your Code
GitLab Duo can explain vulnerability findings in plain language and suggest remediations. Open a security finding and ask for an explanation of the risk and a proposed patch. Always validate the patch against your test suite before merging.
Best Practices
- Treat AI suggestions as drafts, not final code.
- Keep test coverage high so suggestions can be verified.
- Use merge request summaries to speed up reviews.
- Review security patches carefully.
- Give feedback to improve suggestions over time.
Conclusion
GitLab Duo folds AI assistance into the tools your team already uses. Turn it on, accept code suggestions, chat with your repository, and let it summarize merge requests and diagnose pipeline failures. The result is less context switching and faster delivery.
