Skip to content

Commit 2b66a4c

Browse files
authored
NpmAuth Regression Bugfix (#20453)
* Normalize Registries before reading file * Update new service connection name and bump task * Bump packaging-common version * rebuild * bump task version * Fixing alias for WIF input * WIF->AzureDevops
1 parent 59210ec commit 2b66a4c

33 files changed

+111
-101
lines changed

Tasks/NpmAuthenticateV0/Strings/resources.resjson/en-US/resources.resjson

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
"loc.input.help.workingFile": "Path to the .npmrc file that specifies the registries you want to work with. Select the file, not the folder e.g. \"/packages/mypackage.npmrc\". If Azure Artifacts URL and Entra Workload ID-backed Azure DevOps user' Service Connection are set, registries in npmrc will be ignored.",
88
"loc.input.label.customEndpoint": "Credentials for registries outside this organization/collection",
99
"loc.input.help.customEndpoint": "Credentials to use for external registries located in the project's .npmrc. For registries in this organization/collection, leave this blank; the build’s credentials are used automatically.",
10-
"loc.input.label.workloadIdentityServiceConnection": "'Entra Workload ID-backed Azure DevOps user' Service Connection",
10+
"loc.input.label.workloadIdentityServiceConnection": "'Azure DevOps' Service Connection",
1111
"loc.input.help.workloadIdentityServiceConnection": "If this is set, feedUrl is required. Service Connections for external organizations/collection and custom endpoints are not compatible.",
1212
"loc.input.label.feedUrl": "Azure Artifacts URL",
13-
"loc.input.help.feedUrl": "If this is set, workloadIdentityServiceConnection is required. Not compatible with customEndpoint. Feed Url should be in the npm registry format, e.g. https://pkgs.dev.azure.com/{ORG_NAME}/{PROJECT}/_packaging/{FEED_NAME}/npm/registry/",
13+
"loc.input.help.feedUrl": "If this is set, azureDevOpsServiceConnection is required. Not compatible with customEndpoint. Feed Url should be in the npm registry format, e.g. https://pkgs.dev.azure.com/{ORG_NAME}/{PROJECT}/_packaging/{FEED_NAME}/npm/registry/",
1414
"loc.messages.FoundBuildCredentials": "Found build credentials",
1515
"loc.messages.NoBuildCredentials": "Could not find build credentials",
1616
"loc.messages.ServiceEndpointNotDefined": "Couldn't find the service connection. Make sure the selected service connection still exists.",

Tasks/NpmAuthenticateV0/_buildConfigs/Node20/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Tasks/NpmAuthenticateV0/_buildConfigs/Node20/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"homepage": "https://github.com/Microsoft/azure-pipelines-tasks#readme",
1919
"dependencies": {
2020
"azure-pipelines-task-lib": "^4.13.0",
21-
"azure-pipelines-tasks-packaging-common": "^3.242.0",
21+
"azure-pipelines-tasks-packaging-common": "^3.245.0",
2222
"azure-pipelines-tasks-artifacts-common": "^2.243.0",
2323
"@types/mocha": "^5.2.7",
2424
"@types/node": "^20.3.1",

Tasks/NpmAuthenticateV0/_buildConfigs/Wif/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Tasks/NpmAuthenticateV0/_buildConfigs/Wif/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"homepage": "https://github.com/Microsoft/azure-pipelines-tasks#readme",
1919
"dependencies": {
2020
"azure-pipelines-task-lib": "^4.13.0",
21-
"azure-pipelines-tasks-packaging-common": "^3.242.0",
21+
"azure-pipelines-tasks-packaging-common": "^3.245.0",
2222
"azure-pipelines-tasks-artifacts-common": "^2.243.0",
2323
"@types/mocha": "^5.2.7",
2424
"@types/node": "^20.3.1",

Tasks/NpmAuthenticateV0/npmauth.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,17 @@ async function main(): Promise<void> {
7070
fs.writeFileSync(indexFile, JSON.stringify(npmrcTable));
7171
util.saveFileWithName(npmrc, npmrcTable[npmrc], saveNpmrcPath);
7272
}
73-
73+
74+
let packagingLocation: pkgLocationUtils.PackagingLocation;
75+
try {
76+
packagingLocation = await pkgLocationUtils.getPackagingUris(pkgLocationUtils.ProtocolType.Npm);
77+
} catch (error) {
78+
tl.debug('Unable to get packaging URIs');
79+
util.logError(error);
80+
throw error;
81+
}
82+
// Getting local registries will also save normalized registries in the npmrc
83+
let LocalNpmRegistries = await npmutil.getLocalNpmRegistries(workingDirectory, packagingLocation.PackagingUris);
7484
let npmrcFile = fs.readFileSync(npmrc, 'utf8').split(os.EOL);
7585

7686
#if WIF
@@ -133,23 +143,12 @@ async function main(): Promise<void> {
133143
}));
134144
}
135145

136-
let packagingLocation: pkgLocationUtils.PackagingLocation;
137-
try {
138-
packagingLocation = await pkgLocationUtils.getPackagingUris(pkgLocationUtils.ProtocolType.Npm);
139-
} catch (error) {
140-
tl.debug('Unable to get packaging URIs');
141-
util.logError(error);
142-
throw error;
143-
}
144-
let LocalNpmRegistries = await npmutil.getLocalNpmRegistries(workingDirectory, packagingLocation.PackagingUris);
145-
146146
let addedRegistry = [];
147147
for (let RegistryURLString of npmrcparser.GetRegistries(npmrc, /* saveNormalizedRegistries */ true)) {
148148
let registryURL = URL.parse(RegistryURLString);
149149
let registry: npmregistry.NpmRegistry;
150150
if (endpointRegistries && endpointRegistries.length > 0) {
151151
for (let serviceEndpoint of endpointRegistries) {
152-
153152
if (util.toNerfDart(serviceEndpoint.url) == util.toNerfDart(RegistryURLString)) {
154153
let serviceURL = URL.parse(serviceEndpoint.url);
155154
console.log(tl.loc("AddingEndpointCredentials", registryURL.host));

Tasks/NpmAuthenticateV0/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"homepage": "https://github.com/Microsoft/azure-pipelines-tasks#readme",
2020
"dependencies": {
2121
"azure-pipelines-task-lib": "^4.13.0",
22-
"azure-pipelines-tasks-packaging-common": "^3.242.0",
22+
"azure-pipelines-tasks-packaging-common": "^3.245.0",
2323
"azure-pipelines-tasks-artifacts-common": "^2.243.0",
2424
"@types/mocha": "^5.2.7",
2525
"@types/node": "16.18.11",

Tasks/NpmAuthenticateV0/task.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"version": {
1111
"Major": 0,
1212
"Minor": 246,
13-
"Patch": 0
13+
"Patch": 3
1414
},
1515
"runsOn": [
1616
"Agent",

Tasks/NpmAuthenticateV0/task.loc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"version": {
1111
"Major": 0,
1212
"Minor": 246,
13-
"Patch": 0
13+
"Patch": 3
1414
},
1515
"runsOn": [
1616
"Agent",

Tasks/NpmAuthenticateV0/taskJsonOverride.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"inputs": [
33
{
44
"name": "workloadIdentityServiceConnection",
5-
"label": "'Entra Workload ID-backed Azure DevOps user' Service Connection",
5+
"aliases": ["azureDevOpsServiceConnection"],
6+
"label": "'Azure DevOps' Service Connection",
67
"helpMarkDown": "If this is set, feedUrl is required. Service Connections for external organizations/collection and custom endpoints are not compatible.",
78
"type": "connectedService:workloadidentityuser",
89
"required": false,
@@ -14,7 +15,7 @@
1415
{
1516
"name": "feedUrl",
1617
"label": "Azure Artifacts URL",
17-
"helpMarkDown": "If this is set, workloadIdentityServiceConnection is required. Not compatible with customEndpoint. Feed Url should be in the npm registry format, e.g. https://pkgs.dev.azure.com/{ORG_NAME}/{PROJECT}/_packaging/{FEED_NAME}/npm/registry/",
18+
"helpMarkDown": "If this is set, azureDevOpsServiceConnection is required. Not compatible with customEndpoint. Feed Url should be in the npm registry format, e.g. https://pkgs.dev.azure.com/{ORG_NAME}/{PROJECT}/_packaging/{FEED_NAME}/npm/registry/",
1819
"type": "string",
1920
"defaultValue": "",
2021
"required": false

0 commit comments

Comments
 (0)