Use GitLab CI/CD to automatically generate preview links on merge requests, publish your Fern docs when changes are merged to main, and delete preview links after merge.
fern folder (quickstart)Run fern token in your terminal from the directory containing your fern folder. This generates an organization-scoped token that authenticates the Fern CLI in CI/CD.
Copy the token output — you’ll add it to GitLab in the next step.
FERN_TOKEN, paste the token you generated in the previous step as the value, deselect Protect variable, and click Save changes.To post preview links on merge requests, you need a GitLab project access token.
fern-preview)Save the generated token immediately — it won’t be displayed after you leave the page.
Create a .gitlab-ci.yml file in the root of your repository. This pipeline validates your API definition, posts a per-branch preview link on each merge request, publishes your docs when changes are merged to main, and deletes the merged branch’s preview deployment.
Commit and push the .gitlab-ci.yml file to your repository. The pipeline runs automatically on merge requests and when changes are merged to your default branch.