or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

cli-commands.mddangerfile-api.mdgit-utilities.mdgithub-integration.mdindex.mdplatform-integrations.md
tile.json

cli-commands.mddocs/

CLI Commands

Danger.js provides eight CLI commands for different execution contexts, from CI systems to local development workflows.

Capabilities

Primary Commands

danger ci

Runs Danger on CI systems with automatic platform detection.

danger ci [options]

Options:

  • -v, --verbose - Enable verbose logging
  • -t, --text-only - Output to stdout instead of posting comments
  • -d, --dangerfile <path> - Specify custom dangerfile path
  • -i, --id <string> - Unique identifier for multiple Danger runs
  • --use-github-checks - Use GitHub Checks API instead of status API
  • --new-comment - Always create a new comment instead of updating existing
  • --no-publish-check - Don't add Danger check to PR (CI only)

Usage Examples:

# Basic CI usage
danger ci

# With custom dangerfile
danger ci --dangerfile custom-danger.ts

# Multiple Danger runs with unique IDs
danger ci --id lint-check
danger ci --id security-check

# Use GitHub Checks API
danger ci --use-github-checks

danger pr

Runs Danger against an existing pull request locally for testing and development.

danger pr <pr-url> [options]

Parameters:

  • <pr-url> - GitHub, GitLab, or Bitbucket PR URL

Options:

  • -J, --json - Output raw JSON that would be passed to danger process
  • -j, --js - Output human-readable version of the JSON

Usage Examples:

# Analyze GitHub PR
danger pr https://github.com/owner/repo/pull/123

# With custom dangerfile
danger pr https://github.com/owner/repo/pull/123 --dangerfile test-rules.ts

# Text-only output for testing
danger pr https://github.com/owner/repo/pull/123 --text-only

danger local

Runs Danger against local git changes, useful for git hooks or local validation.

danger local [options]

Options:

  • --base <ref> - Base git reference (default: main/master)
  • --staging - Use staged changes instead of committed changes
  • -j, --outputJSON - Output results as JSON to STDOUT

Usage Examples:

# Check changes against main branch
danger local

# Check against specific branch
danger local --base develop

# Check staged changes (for pre-commit hooks)
danger local --staging

danger init

Interactive setup wizard for configuring Danger in a new project.

danger init

Guides through:

  • Platform selection (GitHub, GitLab, Bitbucket)
  • CI system configuration
  • Initial dangerfile creation
  • Token setup instructions

Utility Commands

danger process

Advanced subprocess execution mode for custom integrations and tooling.

danger process <json-file> [options]

Parameters:

  • <json-file> - JSON file containing Danger DSL data

Used internally by Danger and for advanced integrations where you need to pass pre-computed DSL data.

danger runner

Low-level dangerfile execution for internal use and advanced scenarios.

danger runner [options]

Executes dangerfiles directly with minimal setup. Primarily used internally by other Danger commands.

danger reset-status

Resets pull request status to pending state.

danger reset-status [options]

Usage Examples:

# Reset status for current PR
danger reset-status

# Reset with specific ID
danger reset-status --id custom-check

Global Options

Common Options

All commands support these common options:

interface SharedCLI {
  verbose: boolean;                    // -v, --verbose
  textOnly: boolean;                  // -t, --text-only
  externalCiProvider?: string;        // -c, --external-ci-provider
  dangerfile?: string;                // -d, --dangerfile
  id?: string;                        // -i, --id
  failOnErrors: boolean;              // -f, --fail-on-errors
  useGithubChecks: boolean;           // --use-github-checks
  ignoreOutOfDiffComments: boolean;   // --ignore-out-of-diff-comments
  newComment?: boolean;               // --new-comment
  removePreviousComments?: boolean;   // --remove-previous-comments
  outputJSON: boolean;                // --output-json
  process?: string;                   // -p, --process (dev)
  passURLForDSL?: boolean;            // -u, --passURLForDSL (dev)
}

Environment Variables

Danger.js respects several environment variables:

# Platform tokens
DANGER_GITHUB_API_TOKEN=<token>
DANGER_GITLAB_API_TOKEN=<token>
DANGER_BITBUCKETSERVER_USERNAME=<username>
DANGER_BITBUCKETSERVER_PASSWORD=<password>

# Custom API endpoints
DANGER_GITHUB_API_BASE_URL=<url>
DANGER_GITLAB_HOST=<host>

# Debugging
DEBUG=danger:*

CI Platform Integration

GitHub Actions

# .github/workflows/danger.yml
name: Danger
on: [pull_request]
jobs:
  danger:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: '18'
      - run: npm ci
      - run: danger ci
        env:
          DANGER_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}

GitLab CI

# .gitlab-ci.yml
danger:
  stage: test
  script:
    - npm ci
    - danger ci
  only:
    - merge_requests
  variables:
    DANGER_GITLAB_API_TOKEN: $CI_JOB_TOKEN

Jenkins

// Jenkinsfile
pipeline {
  agent any
  stages {
    stage('Danger') {
      when { changeRequest() }
      steps {
        sh 'npm ci'
        sh 'danger ci'
      }
    }
  }
  environment {
    DANGER_GITHUB_API_TOKEN = credentials('github-token')
  }
}

Travis CI

# .travis.yml
language: node_js
node_js:
  - "18"
script:
  - npm test
  - danger ci
env:
  - DANGER_GITHUB_API_TOKEN=$GITHUB_TOKEN

Command Exit Codes

// Exit codes returned by Danger commands
enum ExitCode {
  Success = 0,          // No failures
  Failure = 1,          // Danger failures occurred
  Error = 2,            // Runtime error (missing token, network issues, etc.)
  ConfigError = 3       // Configuration or setup error
}

Advanced Usage

Custom External CI Provider

For unsupported CI systems:

danger ci --external-ci-provider custom-ci

Set these environment variables:

  • CUSTOM_CI_PULL_REQUEST_ID - PR number
  • CUSTOM_CI_REPO_SLUG - Repository identifier (owner/repo)
  • CUSTOM_CI_BASE_SHA - Base commit SHA
  • CUSTOM_CI_HEAD_SHA - Head commit SHA

Multiple Danger Runs

Run multiple Danger configurations in parallel:

# Package.json scripts
{
  "scripts": {
    "danger:lint": "danger ci --id lint --dangerfile dangerfile.lint.ts",
    "danger:security": "danger ci --id security --dangerfile dangerfile.security.ts",
    "danger:docs": "danger ci --id docs --dangerfile dangerfile.docs.ts"
  }
}

JSON Output Mode

For custom integrations and tooling:

danger ci --output-json > danger-results.json

Returns structured JSON with all violations and metadata.