GitLab
OpenCode integrates with your GitLab workflow through your GitLab CI/CD pipeline or with GitLab Duo.
In both cases, OpenCode will run on your GitLab runners.
GitLab CI
OpenCode works in a regular GitLab pipeline. You can build it into a pipeline as a CI component
Here we are using a community-created CI/CD component for OpenCode — nagyv/gitlab-opencode.
Features
- Use custom configuration per job: Configure OpenCode with a custom configuration directory, for example
./config/#custom-directoryto enable or disable functionality per OpenCode invocation. - Minimal setup: The CI component sets up OpenCode in the background, you only need to create the OpenCode configuration and the initial prompt.
- Flexible: The CI component supports several inputs for customizing its behavior
Setup
-
Store your OpenCode authentication JSON as a File type CI environment variables under Settings > CI/CD > Variables. Make sure to mark them as “Masked and hidden”.
-
Add the following to your
.gitlab-ci.ymlfile.include: - component: $CI_SERVER_FQDN/nagyv/gitlab-opencode/opencode@2 inputs: config_dir: ${CI_PROJECT_DIR}/opencode-config auth_json: $OPENCODE_AUTH_JSON # The variable name for your OpenCode authentication JSON command: optional-custom-command message: "Your prompt here"
For more inputs and use cases check out the docs for this component.
GitLab Duo
OpenCode integrates with your GitLab workflow.
Mention @opencode in a comment, and OpenCode will execute tasks within your GitLab CI pipeline.
Features
- Triage issues: Ask OpenCode to look into an issue and explain it to you.
- Fix and implement: Ask OpenCode to fix an issue or implement a feature. It will create a new branch and raise a merge request with the changes.
- Secure: OpenCode runs on your GitLab runners.
Setup
OpenCode runs in your GitLab CI/CD pipeline, here’s what you’ll need to set it up:
- Configure your GitLab environment
- Set up CI/CD
- Get an AI model provider API key
- Create a service account
- Configure CI/CD variables
- Create a flow config file
You can refer to the GitLab CLI agents docs for detailed instructions.
Examples
Here are some examples of how you can use OpenCode in GitLab.
-
Explain an issue
Add this comment in a GitLab issue.
@opencode explain this issueOpenCode will read the issue and reply with a clear explanation.
-
Fix an issue
In a GitLab issue, say:
@opencode fix thisOpenCode will create a new branch, implement the changes, and open a merge request with the changes.
-
Review merge requests
Leave the following comment on a GitLab merge request.
@opencode review this merge requestOpenCode will review the merge request and provide feedback.