> For the complete documentation index, see [llms.txt](https://gitbook.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gitbook.com/docs/documentation/ja-gitbook-documentation/kontentsuwosuru/openapi/guides/support-for-ci-cd-with-api-blocks.md).

# CI/CD との統合

GitBook で OpenAPI スペックの更新を自動化する方法を学びましょう

GitBook は、OpenAPI 仕様の管理に現在使用しているあらゆる CI/CD パイプラインと連携できます。GitBook CLI を使えば、API リファレンスの更新を自動化できます。

### 仕様ファイルをアップロードする

CI プロセス中に OpenAPI 仕様が生成される場合は、ビルド環境から直接アップロードできます。

```bash
# GitBook API トークンを環境変数として設定する
export GITBOOK_TOKEN=<api-token>

gitbook openapi publish \
  --spec spec_name \
  --organization organization_id \
  example.openapi.yaml
```

### 新しいソース URL を設定するか、更新を実行する

OpenAPI 仕様が URL でホストされている場合、GitBook は更新を自動的に確認します。更新を強制するには（たとえば、リリース後など）、次を実行します。

```bash
# GitBook API トークンを環境変数として設定する
export GITBOOK_TOKEN=<api-token>

gitbook openapi publish \
  --spec spec_name \
  --organization organization_id \
  https://api.example.com/openapi.yaml
```

### GitHub Actions で仕様を更新する

OpenAPI 仕様を公開するワークフローを設定する場合は、リポジトリで次の手順を行います。

1. リポジトリで「設定 → シークレットと変数 → Actions」に移動します。
2. シークレットを追加します。 `GITBOOK_TOKEN` （GitBook API トークン）。
3. 変数を追加します（またはワークフローに直接記述します）。
   * `GITBOOK_SPEC_NAME` → GitBook における仕様の名前
   * `GITBOOK_ORGANIZATION_ID` → GitBook の組織 ID
4. ワークフローファイルを次の名前で保存します。 `.github/workflows/gitbook-openapi-publish.yml`.
5. 変更を「main」にプッシュします（またはワークフローを手動で実行します）。

その後、このアクションを使って仕様を更新できます。

{% code title=".github/workflows/gitbook-openapi-publish.yml" %}

```yaml
name: GitBook に OpenAPI を公開

on:
  push:
    branches: [ "main" ]
    paths:
      - "**/*.yaml"
      - "**/*.yml"
      - "**/*.json"
  workflow_dispatch:

jobs:
  publish:
    runs-on: ubuntu-latest
    env:
      # 必須のシークレット
      GITBOOK_TOKEN: ${{ secrets.GITBOOK_TOKEN }}
      # リポジトリまたは組織の変数を優先し、必要に応じて文字列を直接記述
      GITBOOK_SPEC_NAME: ${{ vars.GITBOOK_SPEC_NAME }}
      GITBOOK_ORGANIZATION_ID: ${{ vars.GITBOOK_ORGANIZATION_ID }}

    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Publish spec file to GitBook
        run: |
          npx -y @gitbook/cli@latest openapi publish \
            --spec "$GITBOOK_SPEC_NAME" \
            --organization "$GITBOOK_ORGANIZATION_ID" \
            <path_to_spec>
```

{% endcode %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://gitbook.com/docs/documentation/ja-gitbook-documentation/kontentsuwosuru/openapi/guides/support-for-ci-cd-with-api-blocks.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
