> ## Documentation Index
> Fetch the complete documentation index at: https://docs.westyx.cloud/llms.txt
> Use this file to discover all available pages before exploring further.

# CI/CD

> Use the Westyx CLI in automated pipelines without interactive login.

## Token-based auth

In CI/CD environments, set `WESTYX_TOKEN` to an access token. This bypasses all OAuth flows -
no browser, no device code, no stored credentials.

```bash theme={null}
WESTYX_TOKEN=$WESTYX_TOKEN \
WESTYX_TENANT=acme-digital \
WESTYX_PROJECT=backend \
  westyx config get LOG_LEVEL --service=api --format=plain
```

<Warning>
  When `WESTYX_TOKEN` is set, the CLI never reads or writes `config.json`. Tenant and project
  must be provided via `WESTYX_TENANT` / `WESTYX_PROJECT` or `--tenant` / `--project`.
  The token is never refreshed - provide a fresh token on each run.
</Warning>

## Example: read a value in a pipeline

<CodeGroup>
  ```yaml GitLab CI theme={null}
  deploy:
    script:
      - DB_URL=$(WESTYX_TOKEN=$WESTYX_TOKEN westyx secret get DATABASE_URL --service=api --format=plain)
      - echo "Deploying with DB_URL set"
  ```

  ```yaml GitHub Actions theme={null}
  - name: Read config
    env:
      WESTYX_TOKEN: ${{ secrets.WESTYX_TOKEN }}
      WESTYX_TENANT: acme-digital
      WESTYX_PROJECT: backend
    run: |
      LOG_LEVEL=$(westyx config get LOG_LEVEL --service=api --format=plain)
      echo "LOG_LEVEL=$LOG_LEVEL" >> $GITHUB_ENV
  ```
</CodeGroup>

## Example: read multiple values as JSON

```bash theme={null}
westyx config list --service=api --format=json
westyx secret list --service=api --format=json
```

Use `jq` to extract specific fields:

```bash theme={null}
westyx config list --service=api --format=json | jq -r '.[] | select(.key == "LOG_LEVEL") | .value'
```

## Scripting with `--format=plain` and `--quiet`

`--format=plain` prints one value per line with no headers. Combined with `--quiet`, all
affirmation messages are suppressed - only the result is printed to stdout.

```bash theme={null}
# Safe to assign directly - no extra output
DB_HOST=$(westyx config get DB_HOST --service=api --format=plain --quiet)
```

## Exit codes in scripts

Use exit codes to handle errors in shell scripts:

```bash theme={null}
set -e

westyx config set DEPLOY_VERSION "$VERSION" --service=api || {
  echo "Failed to set DEPLOY_VERSION" >&2
  exit 1
}
```

| Code | Meaning                                           |
| ---- | ------------------------------------------------- |
| `0`  | Success                                           |
| `1`  | Network or server error                           |
| `2`  | Invalid arguments or missing `--service`          |
| `3`  | Auth error - token expired or missing permissions |
| `4`  | Partial success (only `dev push`)                 |

## Environment variable reference

| Variable            | Description                                               |
| ------------------- | --------------------------------------------------------- |
| `WESTYX_TOKEN`      | Access token - bypasses all OAuth flows                   |
| `WESTYX_TENANT`     | Active tenant (ID or name)                                |
| `WESTYX_PROJECT`    | Active project (ID or name)                               |
| `WESTYX_ENDPOINT`   | Override the API endpoint                                 |
| `WESTYX_NO_BROWSER` | Force device flow (not needed when `WESTYX_TOKEN` is set) |
