Skip to content

Conversation

@alexo-bunnyshell
Copy link
Contributor

Changes

New bns pipeline logs command

  • Added command to fetch and display workflow job logs from External API
  • Supports automatic environment-to-job discovery (no --job flag required)
  • Multiple output formats: stylish (colored), json, yaml, raw
  • Log filtering by step name (--step flag)
  • Tail support to show last N lines (--tail flag)
  • Follow mode placeholder (--follow flag)

HTTP client for External API

  • New API client in pkg/api/workflow_job/logs.go
  • Supports pagination with automatic page fetching via FetchAllPages()
  • Merges logs across pages when steps span multiple pages
  • Endpoint: GET /v1/workflow_jobs/{id}/logs?offset=0&limit=1000

Automatic workflow job discovery

  • Queries /v1/workflows?environment={id} to find latest workflow
  • Extracts most recent job ID from workflow's jobs array
  • Falls back to --job flag for explicit job selection

Output formatters

  • Stylish: Color-coded output with step headers and timestamps
  • JSON: Structured JSON output for programmatic parsing
  • YAML: Human-readable YAML format
  • Raw: Plain text log messages only

API fixes

  • Fixed API path: /api/v1/workflow-jobs//v1/workflow_jobs/ (External API convention)
  • Fixed authentication: Authorization: BearerX-Auth-Token header
  • Added default scheme https when profile scheme is empty
  • Added minimal debug output with --debug flag

Usage

# Automatic job discovery (finds latest job for environment)
bns pipeline logs my-env

# Follow logs in real-time
bns pipeline logs my-env --follow

# Filter by specific step
bns pipeline logs my-env --step "Deploy webserver"

# Show last 50 log lines
bns pipeline logs my-env --tail 50

# JSON output
bns pipeline logs my-env --output json

# Debug mode (shows API requests)
bns pipeline logs my-env --debug

# Explicit job ID (skips automatic discovery)
bns pipeline logs my-env --job 12

Error Handling

User-friendly error messages for:
- 404: Workflow job not found or no logs available
- 401: Authentication failed (prompts to run bns configure)
- 403: Access forbidden
- 429: Rate limit exceeded
- 502: Unable to retrieve log file from storage

Dependencies

Requires backend PR with:
- /v1/workflow_jobs/{id}/logs endpoint
- getJobs() method in WorkflowResource


ToDo:

Switch to using the SDK instead of using the API directly for WorkflowJobs, Logs (once the SDK is updated)

alexo-bunnyshell and others added 2 commits January 21, 2026 15:11
This commit adds the ability to view pipeline logs (build jobs) via the bns CLI.

Features:
- New `bns pipeline logs` command to fetch and display workflow job logs
- Support for multiple output formats (stylish, json, yaml, raw)
- Pagination support for large log files
- Log filtering by step name (--step flag)
- Tail support to show last N lines (--tail flag)
- Follow mode for streaming logs (--follow flag, placeholder)
- HTTP client for workflow job logs API endpoint
- Four formatters: stylish (colored), json, yaml, and raw

Technical details:
- New API client in pkg/api/workflow_job/logs.go
- Supports pagination with automatic page fetching
- Graceful error handling with user-friendly messages
- Formatters in pkg/formatter/pipeline_logs/

Usage:
  bns pipeline logs <environment-id> [flags]

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Add workflow job discovery via External API /v1/workflows endpoint
- Replace placeholder with full implementation in getLatestWorkflowJobForEnvironment()
- Fix API path from /api/v1/workflow-jobs/ to /v1/workflow_jobs/ (External API uses underscores)
- Fix authentication header from Authorization: Bearer to X-Auth-Token
- Add default scheme "https" when profile.Scheme is empty
- Add minimal debug output showing GET requests when --debug flag is used

This allows users to run `bns pipeline logs <env-id>` without needing to specify --job flag.
The CLI automatically finds the latest workflow for the environment and uses its most recent job.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants