Danger.js provides eight CLI commands for different execution contexts, from CI systems to local development workflows.
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-checksRuns Danger against an existing pull request locally for testing and development.
danger pr <pr-url> [options]Parameters:
<pr-url> - GitHub, GitLab, or Bitbucket PR URLOptions:
-J, --json - Output raw JSON that would be passed to danger process-j, --js - Output human-readable version of the JSONUsage 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-onlyRuns 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 STDOUTUsage 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 --stagingInteractive setup wizard for configuring Danger in a new project.
danger initGuides through:
Advanced subprocess execution mode for custom integrations and tooling.
danger process <json-file> [options]Parameters:
<json-file> - JSON file containing Danger DSL dataUsed internally by Danger and for advanced integrations where you need to pass pre-computed DSL data.
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.
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-checkAll 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)
}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:*# .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.yml
danger:
stage: test
script:
- npm ci
- danger ci
only:
- merge_requests
variables:
DANGER_GITLAB_API_TOKEN: $CI_JOB_TOKEN// 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.yml
language: node_js
node_js:
- "18"
script:
- npm test
- danger ci
env:
- DANGER_GITHUB_API_TOKEN=$GITHUB_TOKEN// 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
}For unsupported CI systems:
danger ci --external-ci-provider custom-ciSet these environment variables:
CUSTOM_CI_PULL_REQUEST_ID - PR numberCUSTOM_CI_REPO_SLUG - Repository identifier (owner/repo)CUSTOM_CI_BASE_SHA - Base commit SHACUSTOM_CI_HEAD_SHA - Head commit SHARun 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"
}
}For custom integrations and tooling:
danger ci --output-json > danger-results.jsonReturns structured JSON with all violations and metadata.