GitLab
GitLab の issue やマージリクエストで OpenCode を使用します。
OpenCode は、GitLab CI/CD パイプライン、または GitLab Duo を通じて、あなたの GitLab ワークフローに統合されます。
どちらの場合も、OpenCode はあなたの GitLab runner 上で実行されます。
GitLab CI
OpenCode は通常の GitLab パイプラインで動作します。CI component (opens in a new tab) としてパイプラインに組み込めます。
ここでは、OpenCode 向けにコミュニティが作成した CI/CD コンポーネント — nagyv/gitlab-opencode (opens in a new tab) を使用します。
Features
- ジョブごとにカスタム設定を使用: OpenCode をカスタム設定ディレクトリ(例:
./config/#custom-directory)で構成し、OpenCode の呼び出しごとに機能を有効化または無効化できます。 - 最小限のセットアップ: CI コンポーネントがバックグラウンドで OpenCode をセットアップするため、あなたは OpenCode の設定と最初のプロンプトを作成するだけで済みます。
- 柔軟: CI コンポーネントは、その動作をカスタマイズするための複数の入力をサポートします。
Setup
-
OpenCode の認証 JSON を、Settings > CI/CD > Variables の下に File タイプの CI 環境変数として保存します。必ず「Masked and hidden」としてマークしてください。
-
.gitlab-ci.ymlファイルに以下を追加します。.gitlab-ci.ymlinclude: - 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"
さらに多くの入力やユースケースについては、このコンポーネントのドキュメントを確認してください (opens in a new tab)。
GitLab Duo
OpenCode はあなたの GitLab ワークフローに統合されます。
コメント内で @opencode とメンションすると、OpenCode は GitLab CI パイプライン内でタスクを実行します。
Features
- issue のトリアージ: OpenCode に issue を調べて説明するよう依頼できます。
- 修正と実装: OpenCode に issue の修正や機能の実装を依頼できます。 OpenCode は新しいブランチを作成し、変更を含むマージリクエストを作成します。
- セキュア: OpenCode はあなたの GitLab runner 上で実行されます。
Setup
OpenCode は GitLab CI/CD パイプライン内で実行されます。セットアップに必要なものは次のとおりです。
Tip: 最新の手順については GitLab docs (opens in a new tab) を確認してください。
-
GitLab 環境を構成する
-
CI/CD をセットアップする
-
AI モデルプロバイダーの API キーを取得する
-
サービスアカウントを作成する
-
CI/CD 変数を構成する
-
フロー設定ファイルを作成する。以下は一例です。
Flow configuration
image: node:22-slim commands: - echo "Installing opencode" - npm install --global opencode-ai - echo "Installing glab" - export GITLAB_TOKEN=$GITLAB_TOKEN_OPENCODE - apt-get update --quiet && apt-get install --yes curl wget gpg git && rm --recursive --force /var/lib/apt/lists/* - curl --silent --show-error --location "https://raw.githubusercontent.com/upciti/wakemeops/main/assets/install_repository" | bash - apt-get install --yes glab - echo "Configuring glab" - echo $GITLAB_HOST - echo "Creating OpenCode auth configuration" - mkdir --parents ~/.local/share/opencode - | cat > ~/.local/share/opencode/auth.json << EOF { "anthropic": { "type": "api", "key": "$ANTHROPIC_API_KEY" } } EOF - echo "Configuring git" - git config --global user.email "[email protected]" - git config --global user.name "OpenCode" - echo "Testing glab" - glab issue list - echo "Running OpenCode" - | opencode run " You are an AI assistant helping with GitLab operations. Context: $AI_FLOW_CONTEXT Task: $AI_FLOW_INPUT Event: $AI_FLOW_EVENT Please execute the requested task using the available GitLab tools. Be thorough in your analysis and provide clear explanations. <important> Please use the glab CLI to access data from GitLab. The glab CLI has already been authenticated. You can run the corresponding commands. If you are asked to summarize an MR or issue or asked to provide more information then please post back a note to the MR/Issue so that the user can see it. You don't need to commit or push up changes, those will be done automatically based on the file changes you make. </important> " - git checkout --branch $CI_WORKLOAD_REF origin/$CI_WORKLOAD_REF - echo "Checking for git changes and pushing if any exist" - | if ! git diff --quiet || ! git diff --cached --quiet || [ --not --zero "$(git ls-files --others --exclude-standard)" ]; then echo "Git changes detected, adding and pushing..." git add . if git diff --cached --quiet; then echo "No staged changes to commit" else echo "Committing changes to branch: $CI_WORKLOAD_REF" git commit --message "Codex changes" echo "Pushing changes up to $CI_WORKLOAD_REF" git push https://gitlab-ci-token:$GITLAB_TOKEN@$GITLAB_HOST/gl-demo-ultimate-dev-ai-epic-17570/test-java-project.git $CI_WORKLOAD_REF echo "Changes successfully pushed" fi else echo "No git changes detected, skipping push" fi variables: - ANTHROPIC_API_KEY - GITLAB_TOKEN_OPENCODE - GITLAB_HOST
詳細な手順については GitLab CLI agents docs (opens in a new tab) を参照してください。
Examples
GitLab で OpenCode を使用する方法の例をいくつか紹介します。
Tip:
@opencodeとは異なるトリガーフレーズを使うように設定できます。
-
issue を説明する GitLab の issue にこのコメントを追加します。
@opencode explain this issueOpenCode は issue を読み、わかりやすい説明を返信します。
-
issue を修正する GitLab の issue で次のように言います。
@opencode fix thisOpenCode は新しいブランチを作成し、変更を実装し、その変更を含むマージリクエストを作成します。
-
マージリクエストをレビューする GitLab のマージリクエストに次のコメントを残します。
@opencode review this merge requestOpenCode はマージリクエストをレビューし、フィードバックを提供します。