Skip to content

Add pipeline simulation with simulate CLI command#21

Merged
noxify merged 10 commits intomainfrom
resolve
Jan 3, 2026
Merged

Add pipeline simulation with simulate CLI command#21
noxify merged 10 commits intomainfrom
resolve

Conversation

@noxify
Copy link
Owner

@noxify noxify commented Jan 2, 2026

🎯 Motivation

GitLab CI pipelines often have complex rules that determine which jobs run based on branches, variables, and other conditions. Understanding which jobs will execute before pushing commits or triggering pipelines is challenging without actually running the pipeline.

💡 Solution

Added a new simulate command that evaluates GitLab CI rules locally to predict which jobs will run without executing the actual pipeline. This helps developers:

  • Preview pipeline behavior before committing
  • Understand complex rule logic
  • Debug why certain jobs are skipped
  • Test different variable combinations

✨ Features

CLI Command:

  • gitlab-ci-builder simulate <path-or-url> with comprehensive options
  • Support for branch, tag, and merge request simulation
  • Multiple output formats: summary, text, table, json, yaml
  • Remote pipeline support with authentication
  • Verbose mode for detailed rule evaluation

Core Functionality:

  • PipelineSimulator class for rule evaluation
  • Proper handling of if, when, rules, and only/except logic
  • Variable expansion in rule conditions
  • Regex pattern matching for branches and tags
  • Manual job detection

Options:

  • -b, --branch - Simulate for specific branch
  • --tag - Simulate for specific tag
  • --mr - Simulate merge request pipeline
  • -v, --variable - Set custom variables
  • -f, --format - Choose output format
  • --show-skipped - Display skipped jobs
  • --verbose - Show detailed rule evaluation

📝 Examples

# Basic simulation
gitlab-ci-builder simulate .gitlab-ci.yml -b main

# With custom variables
gitlab-ci-builder simulate .gitlab-ci.yml -v DEPLOY_ENV=production

# MR pipeline with table output
gitlab-ci-builder simulate .gitlab-ci.yml --mr -f table --show-skipped

# Remote pipeline
gitlab-ci-builder simulate https://gitlab.com/org/repo/-/raw/main/.gitlab-ci.yml -t <token>

Example Output:

📊 Pipeline Simulation Result

════════════════════════════════════════════════════════════
Total Jobs:    5
Will Run:      3
  - Automatic: 2
  - Manual:    1
Will Skip:     2

📋 Stages:
────────────────────────────────────────────────────────────
  build: 1 job(s)
  test: 1 job(s)
  deploy: 1 job(s)

🔧 Jobs:
────────────────────────────────────────────────────────────
  ▶ build-app (build)
  ▶ test-app (test)
  ⚙ deploy-prod (deploy) - Manual

🧪 Testing

  • 13 Integration Tests - API-level tests for PipelineSimulator class

    • Simple pipeline scenarios
    • Advanced rules with branches and variables
    • Complex nested remote includes (4-level deep with MSW)
    • Edge cases and error handling
  • 15 E2E Tests - CLI interface tests with tuistory

    • All CLI options and flags
    • Multiple output formats
    • Branch, tag, and MR simulation
    • Error handling and validation
    • All tests use inline snapshots for precise output verification

Total Test Coverage: 28 tests (all passing ✅)

📚 Documentation

  • Updated README with comprehensive simulate command documentation
  • Added examples for all major use cases
  • Documented all output formats with descriptions
  • Updated changeset with feature details

🚨 Breaking Changes

None - this is a purely additive feature.

📦 Dependencies

  • Added tuistory (dev) - Terminal emulation for E2E tests
  • Added node-pty (dev) - Required by tuistory for pseudo-terminal support

noxify added 9 commits January 2, 2026 15:53
- Added a new command `simulate` to simulate GitLab CI pipeline execution based on variables and rules.
- Introduced `PipelineSimulator` class to handle the simulation logic, including job evaluation based on rules and context.
- Created `RuleEvaluator` class to evaluate rules against the provided context.
- Enhanced job definitions to support rules for conditional execution.
- Updated types to accommodate new simulation features, including support for multiple job inputs and outputs.
- Added comprehensive unit tests to validate simulation behavior under various scenarios, including rules evaluation and job execution order.
@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 2, 2026

Open in StackBlitz

npm i https://pkg.pr.new/noxify/gitlab-ci-builder/@noxify/gitlab-ci-builder@21

commit: 23f46bb

…d template validation

- Introduced tests for remote job extends normalization to ensure string extends are handled correctly.
- Added tests for variable and job merge order, verifying child definitions override parent definitions.
- Implemented tests for rule evaluator, covering AND operator and not-equal operator scenarios.
- Enhanced simulation tests to cover file existence checks, variable interpolation, and various rule conditions.
- Created tests for template extends chain resolution and lenient validation of templates.
- Updated visualization tests to ensure graceful handling of missing includes.
@noxify noxify merged commit e53a7c1 into main Jan 3, 2026
6 checks passed
@noxify noxify deleted the resolve branch January 3, 2026 00:34
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.

1 participant