### Sample Tool Installation Script Source: https://github.com/microsoft/azure-pipelines-tasks/blob/master/docs/tools.md An example demonstrating how to use the ToolInstaller API to download and set up the Node.js tool for a pipeline. ```APIDOC ## Sample Node.js Installation This sample illustrates the usage of the ToolInstaller API within an Azure Pipeline task to install Node.js. ### Code Example ```typescript import tl = require('vsts-task-lib/task'); import tim = require('vsts-task-lib/toolinstaller'); import path = require('path'); async function installNode() { try { let version: string = tl.getInput('version', true); let ti: tim.ToolInstaller = new tim.ToolInstaller('node', version); let osType = tl.osType(); let arch = 'x64'; // Assuming x64 architecture let ext = osType == 'Windows_NT' ? 'zip' : 'tar.gz'; let nodeUrl = `https://nodejs.org/dist/v${version}/node-v${version}-${osType.toLowerCase()}-${arch}.${ext}`; let temp: string = await ti.download(nodeUrl); let extractRoot = await ti.extract(temp, ext); // Prepend the 'bin' directory of the extracted Node.js to the PATH ti.prependPath(path.join(extractRoot, 'bin')); // Optionally, set a tool-specific variable // ti.setToolVariable('NODE_HOME', extractRoot); } catch (err) { tl.setResult(tl.TaskResult.Failed, tl.loc('NodeInstallerFailed', err.message)); } } installNode(); ``` ### Notes - The `version` input is expected to be provided by the pipeline task configuration. - The script dynamically constructs the download URL based on the Node.js version and the agent's operating system and architecture. - Error handling is included to report failures during the installation process. ``` -------------------------------- ### Specify .NET Core SDK/Runtime Version Examples Source: https://github.com/microsoft/azure-pipelines-tasks/blob/master/Tasks/UseDotNetV2/README.md Examples of how to specify the version of .NET Core SDK or runtime to install. Supports exact versions, latest patch versions, and latest minor versions. ```text 2.2.104 ``` ```text 2.2.1 ``` ```text 3.0.100-preview3-010431 ``` ```text 2.1.x ``` ```text 2.x ``` -------------------------------- ### Node.js Installation Sample Source: https://github.com/microsoft/azure-pipelines-tasks/blob/master/docs/tools.md A sample TypeScript implementation for installing a specific version of Node.js using the Tool Installer task. It handles downloading, extracting, and setting the PATH. ```typescript import tl = require('vsts-task-lib/task'); import tim = require('vsts-task-lib/toolinstaller'); async install() { try { let version: string = tl.getInput('version', true); let ti: tim.ToolInstaller = new ToolInstaller('node', version); let arch = 'x64'; var ext = tl.osType() == 'Windows_NT' ? 'zip' : 'tar.gz'; var nodeUrl="https://nodejs.org/dist/v$" + version + "/node-v" + version + "-" + os + "-" + arch; let temp: string = await inst.download(nodeUrl); let extractRoot = await ti.extract(temp); // tool installer knows node binary is in bin folder of extracted tool ti.prependPath(path.join(extractRoot, 'bin')); } catch (err) { tl.setResult(tl.TaskResult.Failed, tl.loc('NodeInstallerFailed', err.message)); } } ``` -------------------------------- ### Install Project Dependencies Source: https://github.com/microsoft/azure-pipelines-tasks/blob/master/docs/contribute.md Installs all necessary npm packages for the project. This command should be run once after cloning the repository. ```bash npm install ``` -------------------------------- ### Install azure-arm-network Package Source: https://github.com/microsoft/azure-pipelines-tasks/blob/master/Tasks/AzureResourceGroupDeploymentV2/Tests/mock_node_modules/azure-arm-network/README.md Use npm to install the Azure Network Management SDK for Node.js. ```bash npm install azure-arm-network ``` -------------------------------- ### Capture Extension Installation Path with Output Variables Source: https://github.com/microsoft/azure-pipelines-tasks/blob/master/Tasks/AzureAppServiceManageV0/README.md When installing multiple extensions, provide a comma-separated list of variable names to capture the local installation path for each extension in the order they appear. This is particularly useful for configuring applications like web.config. ```yaml outputVariable1, outputVariable2 ``` -------------------------------- ### Install azure-arm-resource package Source: https://github.com/microsoft/azure-pipelines-tasks/blob/master/Tasks/AzureResourceGroupDeploymentV2/Tests/mock_node_modules/azure-arm-resource/README.md Use npm to install the necessary package for managing Azure resources. ```bash npm install azure-arm-resource ``` -------------------------------- ### Notation Install Task Configuration Source: https://github.com/microsoft/azure-pipelines-tasks/blob/master/Tasks/NotationV0/docs/sign-images-pipeline.md Use this task to install the Notation CLI. Specify the desired version. ```yaml # install notation - task: Notation@0 inputs: command: 'install' version: '1.0.0' ``` -------------------------------- ### Install azure-arm-compute Package Source: https://github.com/microsoft/azure-pipelines-tasks/blob/master/Tasks/AzureResourceGroupDeploymentV2/Tests/mock_node_modules/azure-arm-compute/README.md Use npm to install the necessary package for managing Azure Compute Resources. ```bash npm install azure-arm-compute ``` -------------------------------- ### Chocolatey Tool Installer Task Demands and Satisfies Source: https://github.com/microsoft/azure-pipelines-tasks/blob/master/docs/tools.md This example illustrates the demands and satisfies clauses for a Chocolatey tool installer task. It demands 'powershell' to run and satisfies the 'chocolatey' capability. ```yaml demands: - "powershell" satisfies: - "chocolatey" ``` -------------------------------- ### Include all test DLLs by pattern Source: https://github.com/microsoft/azure-pipelines-tasks/blob/master/Tasks/VsTestV3/README.md Use this pattern to include all test DLLs that follow common naming conventions like 'Product.Tests.dll' or 'ProductTests.dll', typically found in the 'bin' directory. ```bash **\bin\**\*test.dll **\bin\**\*tests.dll ``` -------------------------------- ### Build and deploy Container App with Image Provided Source: https://github.com/microsoft/azure-pipelines-tasks/blob/master/Tasks/AzureContainerAppsV1/README.md Deploy a Container App using a pre-built image. The `imageToBuild` input specifies the full image name, including the registry, repository, and tag. ```yaml steps: - task: AzureContainerApps@1 displayName: Build and deploy Container App inputs: connectedServiceNameARM: 'azure-subscription-service-connection' appSourcePath: '$(System.DefaultWorkingDirectory)' acrName: 'mytestacr' imageToBuild: 'mytestacr.azurecr.io/app:latest' ``` -------------------------------- ### Install and Pin a Specific Task Version Source: https://github.com/microsoft/azure-pipelines-tasks/blob/master/docs/pinToTaskVersion/pinToTaskVersion.md Installs a specific version of an Azure Pipelines task by running a PowerShell installation script. Replace 'BashV3' with the actual task directory name and ensure the CollectionUrl is correct for your TFS environment. ```powershell $taskDir = _build\Tasks\BashV3 # Replace BashV3 with the name of the task you would like to install. . eviews\pinToTaskVersion\New-TaskInstallScript.ps1 -CollectionUrl http://myserver:8080/tfs/DefaultCollection -taskDir $taskDir ``` -------------------------------- ### Authenticate and List VM Images Source: https://github.com/microsoft/azure-pipelines-tasks/blob/master/Tasks/AzureResourceGroupDeploymentV2/Tests/mock_node_modules/azure-arm-compute/README.md Demonstrates interactive login for authentication and then lists virtual machine images. Ensure you have the 'ms-rest-azure' and 'azure-arm-compute' packages installed. ```javascript var msrestAzure = require('ms-rest-azure'); var computeManagementClient = require('azure-arm-compute'); // Interactive Login // It provides a url and code that needs to be copied and pasted in a browser and authenticated over there. If successful, // the user will get a DeviceTokenCredentials object. msRestAzure.interactiveLogin(function(err, credentials) { var client = new computeManagementClient(credentials, 'your-subscription-id'); client.virtualMachineImages.list('westus', 'MicrosoftWindowsServer', 'WindowsServer', '2012-R2-Datacenter', function(err, result, request, response) { if (err) console.log(err); console.log(result); }); }); ``` -------------------------------- ### Install NPM Separately Source: https://github.com/microsoft/azure-pipelines-tasks/blob/master/docs/contribute.md Installs a specific version of npm globally. Use this if your system's default npm version is too old. ```bash [sudo] npm install npm@5 -g npm -v 5.6.0 ``` -------------------------------- ### Authenticate and List Resources Source: https://github.com/microsoft/azure-pipelines-tasks/blob/master/Tasks/AzureResourceGroupDeploymentV2/Tests/mock_node_modules/azure-arm-resource/README.md Demonstrates how to authenticate using interactive login and then list all resources in a subscription. Ensure you have the correct subscription ID and resource group name. ```javascript var msRestAzure = require('ms-rest-azure'); var resourceManagement = require("azure-arm-resource"); // Interactive Login msRestAzure.interactiveLogin(function(err, credentials) { var client = new resourceManagement.ResourceManagementClient(credentials, groupName, 'your-subscription-id'); client.resources.list(function(err, result) { if (err) console.log(err); console.log(result); }); }); ```