Skip to main content

CI/CD Integration Overview

x-fidelity can be integrated into your CI/CD pipelines to ensure consistent code quality checks across your projects. This guide explains how to set up x-fidelity in various CI/CD environments.

General Setup

Regardless of your CI platform, the basic setup involves:

  1. Installing x-fidelity
  2. Configuring the environment
  3. Running checks
  4. Processing results

Basic Installation

# Install x-fidelity globally
yarn global add x-fidelity
export PATH="$PATH:$(yarn global bin)"

Environment Variables

Set up these environment variables in your CI environment:

# Required for OpenAI integration (optional)
OPENAI_API_KEY=your_api_key
OPENAI_MODEL=gpt-4

# For config server communication
XFI_SHARED_SECRET=your_shared_secret

# For self-signed certificates
NODE_TLS_REJECT_UNAUTHORIZED=0 # Only in trusted environments

Basic Pipeline Step

steps:
- name: Run x-fidelity
run: |
yarn global add x-fidelity
xfidelity . --configServer https://config-server.example.com

Configuration Options

Remote Config Server

Use a remote config server to centralize your rules:

xfidelity . --configServer https://config-server.example.com

Local Configuration

For projects needing local config:

xfidelity . --localConfigPath ./config

Custom Archetype

Specify a custom archetype:

xfidelity . --archetype java-microservice

Plugin Loading

Plugins can be loaded in two ways:

  1. Via CLI option:
xfidelity . -e xfi-plugin-name another-plugin
  1. Via archetype configuration: Plugins specified in the archetype's plugins array will be loaded automatically.

Exit Codes

x-fidelity uses these exit codes:

  • 0: Success - no issues found
  • 1: Fatal issues found or execution error
  • Other codes: Various error conditions

Best Practices

  1. Version Pinning: Pin x-fidelity to specific versions in production pipelines
  2. Config Management: Use a remote config server for centralized management
  3. Error Handling: Add proper error handling in your pipeline
  4. Reporting: Configure result reporting to your team's preferred channels
  5. Caching: Cache dependencies to speed up pipeline execution

Next Steps