# Intégration avec CI/CD

GitBook peut fonctionner avec n’importe quel pipeline CI/CD que vous utilisez déjà pour gérer votre spécification OpenAPI. En utilisant l’interface en ligne de commande GitBook, vous pouvez automatiser les mises à jour de votre référence d’API.

### Télécharger un fichier de spécification

Si votre spécification OpenAPI est générée pendant votre processus CI, vous pouvez la téléverser directement depuis votre environnement de build :

```bash
# Définissez votre jeton d’API GitBook comme variable d’environnement
export GITBOOK_TOKEN=<api-token>

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

### Définir une nouvelle URL source ou déclencher un rafraîchissement

Si votre spécification OpenAPI est hébergée à une URL, GitBook vérifie automatiquement les mises à jour. Pour forcer une mise à jour (par exemple, après une version), exécutez :

```bash
# Définissez votre jeton d’API GitBook comme variable d’environnement
export GITBOOK_TOKEN=<api-token>

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

### Mettre à jour votre spécification avec GitHub Actions

Si vous configurez un workflow pour publier votre spécification OpenAPI, suivez ces étapes dans votre dépôt :

1. Dans votre dépôt, allez dans « Settings → Secrets and variables → Actions ».
2. Ajoutez un secret : `GITBOOK_TOKEN` (votre jeton d’API GitBook).
3. Ajoutez des variables (ou codez-les en dur dans le workflow) :
   * `GITBOOK_SPEC_NAME` → le nom de votre spécification dans GitBook
   * `GITBOOK_ORGANIZATION_ID` → l’ID de votre organisation GitBook
4. Enregistrez le fichier de workflow sous `.github/workflows/gitbook-openapi-publish.yml`.
5. Poussez les modifications vers « main » (ou exécutez le workflow manuellement).

Vous pouvez ensuite utiliser cette action pour mettre à jour votre spécification :

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

```yaml
name: Publier OpenAPI sur GitBook

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

jobs:
  publish:
    runs-on: ubuntu-latest
    env:
      # Secret requis
      GITBOOK_TOKEN: ${{ secrets.GITBOOK_TOKEN }}
      # Préférez les variables du dépôt/de l’organisation ; repli sur des chaînes en dur si vous le souhaitez
      GITBOOK_SPEC_NAME: ${{ vars.GITBOOK_SPEC_NAME }}
      GITBOOK_ORGANIZATION_ID: ${{ vars.GITBOOK_ORGANIZATION_ID }}

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

      - name: Publier le fichier de spécification sur GitBook
        run: |
          npx -y @gitbook/cli@latest openapi publish \
            --spec "$GITBOOK_SPEC_NAME" \
            --organization "$GITBOOK_ORGANIZATION_ID" \
            <path_to_spec>
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://gitbook.com/docs/documentation/fr/api-references/guides/support-for-ci-cd-with-api-blocks.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
