> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://uploadcare.com/docs/llms.txt.

# CLI in CI/CD pipelines

> Use the Uploadcare CLI in automated pipelines — installation, authentication, batch operations, and workflow examples.

The CLI is designed for automation: structured JSON output, predictable exit codes,
environment-variable authentication, and no interactive prompts.

## Setup in CI

**Install the CLI in a setup step:**

```bash
curl -fsSL https://raw.githubusercontent.com/uploadcare/uploadcare-cli/main/scripts/install.sh | sh
```

**Pin a specific version** to keep builds reproducible:

```bash
curl -fsSL https://raw.githubusercontent.com/uploadcare/uploadcare-cli/main/scripts/install.sh | VERSION=0.1.0 sh
```

**Install to a custom directory** (e.g., when `/usr/local/bin` is not writable):

```bash
curl -fsSL https://raw.githubusercontent.com/uploadcare/uploadcare-cli/main/scripts/install.sh | INSTALL_DIR=./bin sh
```

**Authenticate via environment variables:**

Set `UPLOADCARE_PUBLIC_KEY` and `UPLOADCARE_SECRET_KEY` in your CI platform's
secret management system.

> **Warning**
>
> **Warning:** Never hardcode API keys in pipeline configuration files. Use your platform's secrets
> or environment variable management instead.

## Exit codes

The CLI uses predictable exit codes so scripts can branch on success or failure:

| Code | Meaning              | Example cause                         |
| ---- | -------------------- | ------------------------------------- |
| 0    | Success              | Operation completed                   |
| 1    | API or runtime error | File not found, partial batch failure |
| 2    | Usage error          | Invalid flags, bad UUID format        |
| 3    | Auth or config error | Missing or invalid credentials        |

**Use in shell conditionals:**

```bash
if uploadcare file upload build/output.zip --json uuid; then
  echo "Upload succeeded"
else
  echo "Upload failed with exit code $?"
  exit 1
fi
```

**Batch operations return exit code 1 for partial failures.** The JSON output includes
a `problems` field with per-file error details:

```bash
uploadcare file store UUID1 UUID2 UUID3 --json all
# Exit code 1 if some UUIDs had errors, 0 if all succeeded
```

## GitHub Actions example

```yaml
name: Upload assets to Uploadcare
on:
  push:
    branches: [main]

jobs:
  upload:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Install Uploadcare CLI
        run: curl -fsSL https://raw.githubusercontent.com/uploadcare/uploadcare-cli/main/scripts/install.sh | sh

      - name: Build
        run: npm run build

      - name: Upload build artifacts
        env:
          UPLOADCARE_PUBLIC_KEY: ${{ secrets.UPLOADCARE_PUBLIC_KEY }}
          UPLOADCARE_SECRET_KEY: ${{ secrets.UPLOADCARE_SECRET_KEY }}
        run: |
          uploadcare file upload dist/assets/*.js --store true --json uuid,filename
```

## Batch operations

**Upload all files in a directory:**

```bash
uploadcare file upload ./images/*.jpg --store true --json uuid,filename
```

**Upload file paths from stdin:**

```bash
find ./images -name '*.png' | uploadcare file upload --from-stdin --json uuid
```

**Delete all unstored files:**

```bash
uploadcare file list --page-all --stored false --json uuid | uploadcare file delete --from-stdin
```

**Store all temporary files:**

```bash
uploadcare file list --page-all --stored false --json uuid | uploadcare file store --from-stdin
```

**Preview destructive operations with dry-run:**

```bash
uploadcare file list --page-all --stored false --json uuid | uploadcare file delete --from-stdin --dry-run
```

## Webhook management during deployment

Register or update webhooks as part of your deployment process:

**Create a webhook:**

```bash
uploadcare webhook create https://api.example.com/hooks/upload --event file.uploaded
```

**Update a webhook URL on deploy:**

```bash
uploadcare webhook update 12345 --target-url https://api-v2.example.com/hooks/upload
```

**List current webhooks:**

```bash
uploadcare webhook list --json id,target_url,event,is_active
```

## Multi-environment management

Use named projects or the `--project` flag to target different environments:

```bash
# Deploy to staging
uploadcare file upload ./assets/* --project "Staging" --store true

# Deploy to production
uploadcare file upload ./assets/* --project "Production" --store true
```

In CI, switch environments via the `UPLOADCARE_PROJECT` variable:

```yaml
jobs:
  deploy-staging:
    env:
      UPLOADCARE_PROJECT: "Staging"
    steps:
      - run: uploadcare file upload ./assets/*

  deploy-production:
    env:
      UPLOADCARE_PROJECT: "Production"
    steps:
      - run: uploadcare file upload ./assets/*
```

See [Configuration](/docs/cli/configuration/#multi-project-setup) for setting up named projects.