Taskcluster Client for JavaScript
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
-
Error: Failed to list tasks: Unauthorized (401)
cause Missing or incorrect `clientId` or `accessToken`, or insufficient scopes assigned to the credentials.fixEnsure `credentials.clientId` and `credentials.accessToken` are correctly provided and the associated client has the necessary scopes for the API calls being made. For temporary credentials, also verify `credentials.certificate`. -
Failed to list tasks: connect ECONNREFUSED <host>:<port>
cause The `rootUrl` provided is incorrect or the Taskcluster instance is unreachable/down.fixVerify that the `rootUrl` is correct and the Taskcluster instance it points to is accessible from where your client code is running. Check network connectivity or firewall rules. -
Error: OutOfMemoryError: JavaScript heap out of memory
cause Processing very large log artifacts or other large data streams entirely in memory without streaming.fixFor operations involving large artifacts (e.g., GitHub service log streaming), ensure your `taskcluster-client` version is up-to-date (>=98.0.1) as recent versions include fixes to stream artifacts rather than downloading them entirely into memory. For custom logic, implement streaming where possible.
Warnings
- breaking The `taskcluster/websocktunnel` Docker image tags underwent a breaking change. Users relying on specific tags for this image may need to update their configurations.
- breaking Generic Worker now correctly evaluates absolute paths within `mounts` (properties `directory` and `file`) and artifacts (property `path`). Previously, Generic Worker effectively stripped these absolute paths, leading to incorrect file resolution.
- gotcha The `taskcluster.fromEnvVars()` utility function does not respect the `TASKCLUSTER_PROXY_URL` environment variable. If you are running client code within a Taskcluster task that needs to communicate via the proxy, manually set `rootUrl`.
- gotcha This library frequently updates its required Node.js version, often including security updates. Running with an older Node.js version can lead to compatibility issues or missed security patches.
- breaking Azure provider workers were previously getting stuck in `STOPPING` indefinitely if their backing Azure resources were deleted out-of-band. While fixed in v99.1.1, older versions will exhibit this behavior, causing resource leaks or stalled deployments.
Install
-
npm install taskcluster-client -
yarn add taskcluster-client -
pnpm add taskcluster-client
Imports
- taskcluster
const taskcluster = require('taskcluster-client');import taskcluster from 'taskcluster-client';
- QueueClient
import { Queue } from 'taskcluster-client';import taskcluster from 'taskcluster-client'; const queue = new taskcluster.Queue(...);
- fromEnvVars
import { fromEnvVars } from 'taskcluster-client';import taskcluster from 'taskcluster-client'; const config = taskcluster.fromEnvVars();
Quickstart
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();