Codefresh CLI

1.1.3 · active · verified Sun Apr 19

The `codefresh` package provides the official command-line interface (CLI) for interacting with the Codefresh platform, enabling users to manage CI/CD pipelines, deployments, and various resources directly from their terminal. It supports a wide array of operations including managing builds, images, tags, authentication contexts, and Helm releases. The current stable version is 1.1.3. Releases appear to be frequent, often weekly or bi-weekly, addressing bugs, security updates, and new features. Its primary differentiator is providing a comprehensive, scriptable interface to Codefresh's full suite of CI/CD capabilities, serving as a powerful tool for automation and integration within development workflows. It requires Node.js v24.0.0 or higher to run.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates global installation of the Codefresh CLI, authentication using an API key from environment variables, and fetching the CLI version and configured contexts programmatically.

import { execa } from 'execa'; // npm install execa

async function setupAndUseCodefreshCLI() {
  console.log('--- Installing Codefresh CLI globally ---\n');
  try {
    await execa('npm', ['install', '-g', 'codefresh'], { stdio: 'inherit' });
    console.log('\nCodefresh CLI installed successfully.\n');
  } catch (error) {
    console.error('Failed to install Codefresh CLI:', error.message);
    return;
  }

  const apiKey = process.env.CODEFRESH_API_KEY ?? '';
  if (!apiKey) {
    console.error('CODEFRESH_API_KEY environment variable is not set. Please generate an API key from Codefresh account settings and set it.\n');
    return;
  }

  console.log('--- Authenticating with Codefresh CLI ---\n');
  try {
    await execa('codefresh', ['auth', 'create-context', '--api-key', apiKey], { stdio: 'inherit' });
    console.log('\nAuthentication successful. Context created.\n');
  } catch (error) {
    console.error('Authentication failed. Check your API key and network connection:', error.message);
    return;
  }

  console.log('--- Getting Codefresh CLI version ---\n');
  try {
    const { stdout } = await execa('codefresh', ['version']);
    console.log(`Codefresh CLI Version: ${stdout.trim()}\n`);
  } catch (error) {
    console.error('Failed to get CLI version:', error.message);
  }

  console.log('--- Listing Codefresh contexts (example) ---\n');
  try {
    const { stdout } = await execa('codefresh', ['get', 'contexts']);
    console.log('Codefresh Contexts:\n', stdout);
  } catch (error) {
    console.error('Failed to list contexts:', error.message);
  }
}

setupAndUseCodefreshCLI();

view raw JSON →