OpenCode GitLab
OpenCode can also be integrated into GitLab workflows, automatically executing tasks in Issues, Merge Requests, and CI/CD pipelines.
Its core feature is running on your GitLab Runner, enabling secure and controllable AI-driven automated development.
OpenCode GitLab = Integrating AI into CI/CD, automating code analysis, fixes, and reviews.
1. Integration Methods Overview
OpenCode has two main usage methods in GitLab:
- GitLab CI (Recommended): Execute OpenCode through CI/CD pipelines
- GitLab Duo (Comment Triggered): Trigger via @opencode in comments
2. GitLab CI Integration (Core Method)
OpenCode can be integrated into your pipeline as a CI component to automate task execution.
Here we use the community component:
nagyv/gitlab-opencode
1. Features
- Custom configuration per task: Supports independent configuration directories
- Minimal integration cost: No complex initialization required
- Highly customizable: Supports multi-parameter behavior control
2. Configuration Steps
① Configure authentication information
In your GitLab project:
- Go to Settings → CI/CD → Variables
- Add variables:
OPENCODE_AUTH_JSON
Requirements:
- Type: File
- Check Masked and Hidden
② Configure the pipeline
Create or modify in the project root:
.gitlab-ci.yml
Example:
include:
- component: $CI_SERVER_FQDN/nagyv/gitlab-opencode/opencode@2
inputs:
config_dir: ${CI_PROJECT_DIR}/opencode-config
auth_json: $OPENCODE_AUTH_JSON
command: optional-custom-command
message: "Explain the codebase structure"
③ Parameter description
| Parameter | Description |
|---|---|
| config_dir | OpenCode configuration directory |
| auth_json | Authentication information (API Key) |
| command | Execution command (optional) |
| message | Prompt |
3. Use Cases
- Automatically analyze code structure
- Batch refactor code
- Automatically generate documentation
- Automatically check code quality during CI stages
3. GitLab Duo Integration (Comment Triggered)
Similar to GitHub's /opencode, GitLab uses@opencodeto trigger.
When you comment on an Issue or Merge Request:
@opencode your prompt
OpenCode will automatically execute tasks in GitLab CI
1. Features
- Issue analysis: Automatically understand issues
- Automatic fixes: Create a branch and submit an MR
- Code review: Analyze Merge Requests
Features:
- Runs on GitLab Runner
- Secure, does not rely on external execution environments
2. Configuration Steps
To use @opencode, you need to complete the following configuration:
- Configure GitLab CI/CD pipeline
- Prepare API Key
- Create a Service Account
- Configure CI/CD Variables
- Create Flow configuration file
Note:
For specific details, refer to the GitLab CLI Agents official documentation (varies slightly between versions).
4. Common Usage
1. Explain Issues
@opencode explain this issue
Automatically summarize issues and provide explanations
2. Automatically Fix Issues
@opencode fix this
Automatically:
- Create a new branch
- Modify code
- Submit a Merge Request
3. Review Merge Requests
@opencode review this merge request
Automatically analyze:
- Code quality
- Potential bugs
- Optimization suggestions
5. Advanced Tips
1. Custom Trigger Words
You can@opencodereplace it with other trigger keywords.
2. Task-Level Configuration
By using different config_dir, you can achieve:
- Different models for different tasks
- Different rules for different projects
3. Integrating with CI Automation
You can achieve:
- Scheduled code issue scanning
- Automatic weekly report generation
- Automatically fix simple bugs
6. Security and Best Practices
- Use CI/CD Variables to store secrets
- Avoid hardcoding API Keys in code
- Reasonably control Runner permissions
- Limit the scope of automatic code modifications