# Open a maintenance window from your deploy pipeline Silence alerts while a deploy runs, show the work on your status page, and close the window when the deploy is done. Your pipeline opens the window first and completes it at the end, even if the deploy fails. On GitHub Actions, the [InfraNest Maintenance Window](../open-source.md#github-action) action does all of this for you. The steps below work in any CI. **Runnable code:** the code on this page, ready to clone and run, is in [`infranest-examples/examples/maintenance-window`](https://github.com/InfraNest-Infrastructure-Organized/infranest-examples/tree/main/examples/maintenance-window). CI runs it against the [sandbox](../sandbox.md). ## The token Make a token with **Monitoring → Write**. Store it as a secret in your CI, for example `INFRANEST_TOKEN`. ## Open the window ```sh WINDOW_ID=$(curl -fsS -X POST https://api.infranest.io/api/organizations/42/maintenance-windows \ -H "Authorization: Bearer $INFRANEST_TOKEN" \ -H "Content-Type: application/json" \ -H "Idempotency-Key: deploy-$CI_PIPELINE_ID" \ -d '{ "name": "Deploy of the web app", "starts_at": "'"$(date -u +%Y-%m-%dT%H:%M:%SZ)"'", "ends_at": "'"$(date -u -d '+30 minutes' +%Y-%m-%dT%H:%M:%SZ)"'", "suppress_alerts": true, "check_ids": [1201, 1202] }' | jq -r .id) ``` - **`check_ids`** are the monitors to silence. Find them with `GET /organizations/42/monitoring-checks`. Use `server_ids` for servers. - **`ends_at`** is a safety net: if the pipeline never completes the window, it still closes then. - **The `Idempotency-Key`** uses the pipeline's id, so a retried job step opens one window, not two. See [Retries and dry runs](../retries-and-dry-runs.md). On macOS, `date -d` is not available. Use `date -u -v+30M +%Y-%m-%dT%H:%M:%SZ` instead. ## Close it when the deploy is done ```sh curl -fsS -X PATCH "https://api.infranest.io/api/organizations/42/maintenance-windows/$WINDOW_ID/complete" \ -H "Authorization: Bearer $INFRANEST_TOKEN" -H "Accept: application/json" ``` Run this step whether the deploy succeeded or failed (in GitHub Actions, `if: always()`; in GitLab CI, an `after_script`). Alerts resume as soon as the window is complete.