This package contains an isomorphic SDK for BatchServiceClient.
- Node.js version 6.x.x or higher
- Browser JavaScript
npm install @azure/batch
npm install @azure/ms-rest-nodeauth
- Use
AzureCliCredentials
exported from@azure/ms-rest-nodeauth
. Please make sure to install Azure CLI and login usingaz login
.
import { AzureCliCredentials } from "@azure/ms-rest-nodeauth";
const batchEndpoint = process.env["AZURE_BATCH_ENDPOINT"] || "";
async function main(): Promise<void> {
try {
const creds = await AzureCliCredentials.create({ resource: "https://batch.core.windows.net/" });
const client = new BatchServiceClient(creds, batchEndpoint);
} catch (err) {
console.log(err);
}
}
- Use the
BatchSharedKeyCredentials
exported from@azure/batch
.
import { BatchServiceClient, BatchSharedKeyCredentials } from "@azure/batch";
const batchAccountName = process.env["AZURE_BATCH_ACCOUNT_NAME"] || "";
const batchAccountKey = process.env["AZURE_BATCH_ACCOUNT_KEY"] || "";
const batchEndpoint = process.env["AZURE_BATCH_ENDPOINT"] || "";
async function main(): Promise<void> {
try {
const creds = new BatchSharedKeyCredentials(batchAccountName, batchAccountKey);
const client = new BatchServiceClient(creds, batchEndpoint);
} catch (err) {
console.log(err);
}
}
- Use the
MSIVmTokenCredentials
exported from@azure/ms-rest-nodeauth
.
import { MSIVmTokenCredentials } from "@azure/ms-rest-nodeauth";
const batchEndpoint = process.env["AZURE_BATCH_ENDPOINT"] || "";
async function main(): Promise<void> {
try {
const creds = await msRestNodeAuth.loginWithVmMSI({
resource: "https://batch.core.windows.net/"
});
const client = new BatchServiceClient(creds, batchEndpoint);
} catch (err) {
console.log(err);
}
}
import { BatchServiceClient, BatchServiceModels, BatchSharedKeyCredentials } from "@azure/batch";
const batchAccountName = process.env["AZURE_BATCH_ACCOUNT_NAME"] || "";
const batchAccountKey = process.env["AZURE_BATCH_ACCOUNT_KEY"] || "";
const batchEndpoint = process.env["AZURE_BATCH_ENDPOINT"] || "";
const creds = new BatchSharedKeyCredentials(batchAccountName, batchAccountKey);
const client = new BatchServiceClient(creds, batchEndpoint);
const options: BatchServiceModels.JobListOptionalParams = {
jobListOptions: { maxResults: 10 }
};
async function loop(res: BatchServiceModels.JobListResponse, nextLink?: string): Promise<void> {
if (nextLink !== undefined) {
const res1 = await client.job.listNext(nextLink);
if (res1.length) {
for (const item of res1) {
res.push(item);
}
}
return loop(res, res1.odatanextLink);
}
return Promise.resolve();
}
async function main(): Promise<void> {
const result = await client.job.list(options);
await loop(result, result.odatanextLink);
console.dir(result, { depth: null, colors: true });
}
main().catch((err) => console.log("An error occurred: ", err));