From ef372848a775b94480c80bdc8d1b54e3ab6b8b19 Mon Sep 17 00:00:00 2001 From: Brian Dukes Date: Tue, 19 May 2026 12:42:59 -0500 Subject: [PATCH] Add versionFilePath to UseNode@1 Fixes #22131 --- .../Strings/resources.resjson/en-US/resources.resjson | 2 ++ Tasks/UseNodeV1/task.json | 7 +++++++ Tasks/UseNodeV1/task.loc.json | 7 +++++++ Tasks/UseNodeV1/usenode.ts | 11 ++++++++++- 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/Tasks/UseNodeV1/Strings/resources.resjson/en-US/resources.resjson b/Tasks/UseNodeV1/Strings/resources.resjson/en-US/resources.resjson index bf2f0db3158f..48a916e9a540 100644 --- a/Tasks/UseNodeV1/Strings/resources.resjson/en-US/resources.resjson +++ b/Tasks/UseNodeV1/Strings/resources.resjson/en-US/resources.resjson @@ -5,6 +5,8 @@ "loc.instanceNameFormat": "Use Node $(versionSpec)", "loc.input.label.version": "Version", "loc.input.help.version": "Version Spec of the version to use. Examples: 10.x, 10.15.1, >=10.15.0", + "loc.input.label.versionFilePath": "Version File Path", + "loc.input.help.versionFilePath": "File path to get version. Example: src/.nvmrc", "loc.input.label.checkLatest": "Check for Latest Version", "loc.input.help.checkLatest": "Always checks online for the latest available version that satisfies the version spec. This is typically false unless you have a specific scenario to always get latest. This will cause it to incur download costs when potentially not necessary, especially with the hosted build pool.", "loc.input.label.force32bit": "Use 32 bit version on x64 agents", diff --git a/Tasks/UseNodeV1/task.json b/Tasks/UseNodeV1/task.json index d49219dbcd0e..664fefd46551 100644 --- a/Tasks/UseNodeV1/task.json +++ b/Tasks/UseNodeV1/task.json @@ -35,6 +35,13 @@ "required": false, "helpMarkDown": "Version Spec of the version to use. Examples: 10.x, 10.15.1, >=10.15.0" }, + { + "name": "versionFilePath", + "type": "string", + "label": "Version File Path", + "required": false, + "helpMarkDown": "File path to get version. Example: src/.nvmrc" + }, { "name": "checkLatest", "type": "boolean", diff --git a/Tasks/UseNodeV1/task.loc.json b/Tasks/UseNodeV1/task.loc.json index 4683b7500d8a..838afd48f21e 100644 --- a/Tasks/UseNodeV1/task.loc.json +++ b/Tasks/UseNodeV1/task.loc.json @@ -35,6 +35,13 @@ "required": false, "helpMarkDown": "ms-resource:loc.input.help.version" }, + { + "name": "versionFilePath", + "type": "string", + "label": "ms-resource:loc.input.label.versionFilePath", + "required": false, + "helpMarkDown": "ms-resource:loc.input.help.versionFilePath" + }, { "name": "checkLatest", "type": "boolean", diff --git a/Tasks/UseNodeV1/usenode.ts b/Tasks/UseNodeV1/usenode.ts index 99a09f57e3b6..eef88ad780d8 100644 --- a/Tasks/UseNodeV1/usenode.ts +++ b/Tasks/UseNodeV1/usenode.ts @@ -12,6 +12,7 @@ import * as taskLib from 'azure-pipelines-task-lib/task'; import * as installer from './installer'; import * as proxyutil from './proxyutil'; import * as path from 'path'; +import * as fs from 'fs'; async function run() { try { @@ -20,7 +21,7 @@ async function run() { // If not supplied then task is still used to setup proxy, auth, etc... // taskLib.setResourcePath(path.join(__dirname, 'task.json')); - const version = taskLib.getInput('version', false); + const version = getNodeVersion(taskLib.getInput('version', false), taskLib.getInput('versionFilePath', false)); const nodejsMirror = taskLib.getInput('nodejsMirror', false) || 'https://nodejs.org/dist/'; const retryCountOnDownloadFails = taskLib.getInput('retryCountOnDownloadFails', false) || "5"; const delayBetweenRetries = taskLib.getInput('delayBetweenRetries', false) || "1000"; @@ -39,4 +40,12 @@ async function run() { } } +function getNodeVersion(versionSpecInput: string, versionFilePathInput: string) { + if (versionFilePathInput) { + return fs.readFileSync(versionFilePathInput, { 'encoding': 'utf8' }); + } + + return versionSpecInput; +} + run() \ No newline at end of file