Taskcluster Client for JavaScript

87.1.3 · active · verified Wed Apr 22

taskcluster-client is the official JavaScript client library for interfacing with Taskcluster components, providing a comprehensive asynchronous interface for all Taskcluster API methods. Primarily designed for server-side Node.js applications, it is deeply integrated into the Taskcluster ecosystem for inter-service communication. The current stable version, as per recent releases, is v99.1.1. The package maintains an active release cadence, frequently incorporating patch and minor updates that include critical Node.js (currently requiring v24.15.0 or later) and Go security upgrades, along with enhancements to worker deployment and monitoring. Key differentiators include robust retry mechanisms for transient network errors and flexible authentication options supporting both environment variables and direct credential provision, ensuring secure and reliable interaction with Taskcluster services.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to instantiate a Taskcluster client, configure it with credentials (from env vars or directly), and use the Queue service to list recent tasks. It highlights error handling for common authentication issues.

import taskcluster from 'taskcluster-client';
import { URL } from 'url';

// Load credentials from environment variables, or specify directly
const clientOptions = {
  ...taskcluster.fromEnvVars(),
  // Override rootUrl if TASKCLUSTER_PROXY_URL is desired in a task
  rootUrl: process.env.TASKCLUSTER_PROXY_URL || 'https://taskcluster.net',
  credentials: {
    clientId: process.env.TASKCLUSTER_CLIENT_ID || '',
    accessToken: process.env.TASKCLUSTER_ACCESS_TOKEN || '',
    certificate: process.env.TASKCLUSTER_CERTIFICATE ? JSON.parse(process.env.TASKCLUSTER_CERTIFICATE) : undefined
  },
  timeout: 60 * 1000, // 60-second timeout per request
  retries: 3
};

// Instantiate the Queue Client class
const queue = new taskcluster.Queue(clientOptions);

async function listTasks() {
  try {
    console.log(`Attempting to list tasks from ${clientOptions.rootUrl}...`);
    // For this example, we'll try to get the latest 10 tasks.
    // Note: 'listTasks' often requires appropriate scopes and context.
    const { tasks } = await queue.listLatestTasks({ limit: 10 });
    console.log(`Successfully retrieved ${tasks.length} tasks.`);
    for (const task of tasks) {
      console.log(`  Task ID: ${task.taskId}, State: ${task.state}`);
    }
  } catch (error) {
    console.error('Failed to list tasks:', error.message);
    if (error.statusCode === 401 || error.statusCode === 403) {
      console.error('Check your Taskcluster credentials and scopes.');
    }
  }
}

listTasks();

view raw JSON →