Skip to content

Commit 41e75b6

Browse files
gavinbarronCopilot
andauthored
fix: use private npm feed in CI to bypass network isolation (#3564)
Add tools/Configure-PrivateNpmFeed.ps1 script that creates .npmrc files pointing to the Azure Artifacts PowerShell_V2_Build npm feed. Update install-tools.yml to run the script and authenticate via npmAuthenticate before installing autorest and rush. Two .npmrc files are configured at build time: - Repo root: for global npm install commands (autorest, rush CLI) - autorest.powershell/common/config/rush/.npmrc: for rush install The Rush .npmrc in the repo retains the public registry default so external contributors can still install from registry.npmjs.org. Fixes #3563 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 38a2c6f commit 41e75b6

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

.azure-pipelines/common-templates/install-tools.yml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,25 @@ steps:
2929
displayName: Install NodeJs
3030
inputs:
3131
versionSpec: 18.x
32-
32+
33+
- task: PowerShell@2
34+
displayName: Configure private npm feed
35+
inputs:
36+
targetType: filePath
37+
pwsh: true
38+
filePath: $(Build.SourcesDirectory)/tools/Configure-PrivateNpmFeed.ps1
39+
arguments: -SourcesDirectory "$(Build.SourcesDirectory)"
40+
41+
- task: npmAuthenticate@0
42+
displayName: Authenticate to private npm feed
43+
inputs:
44+
workingFile: $(Build.SourcesDirectory)/.npmrc
45+
46+
- task: npmAuthenticate@0
47+
displayName: Authenticate to private npm feed (Rush)
48+
inputs:
49+
workingFile: $(Build.SourcesDirectory)/autorest.powershell/common/config/rush/.npmrc
50+
3351
- task: Npm@1
3452
displayName: Install AutoRest
3553
inputs:

tools/Configure-PrivateNpmFeed.ps1

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
<#
5+
.SYNOPSIS
6+
Configures .npmrc files to use a private Azure Artifacts npm feed.
7+
8+
.DESCRIPTION
9+
Creates .npmrc files at the repository root and in the Rush config directory
10+
to redirect npm and Rush package installations to a private feed. This is
11+
used in CI pipelines where network isolation rules block the public npm registry.
12+
13+
.PARAMETER SourcesDirectory
14+
The root directory of the repository. Defaults to the current directory.
15+
16+
.PARAMETER Registry
17+
The private npm registry URL.
18+
#>
19+
param(
20+
[Parameter()]
21+
[string]$SourcesDirectory = (Get-Location).Path,
22+
23+
[Parameter()]
24+
[string]$Registry = "https://microsoftgraph.pkgs.visualstudio.com/0985d294-5762-4bc2-a565-161ef349ca3e/_packaging/PowerShell_V2_Build/npm/registry/"
25+
)
26+
27+
$npmrcContent = "registry=$Registry`nalways-auth=true"
28+
29+
# Create .npmrc at repo root for global npm installs (autorest, rush)
30+
$rootNpmrc = Join-Path $SourcesDirectory ".npmrc"
31+
Set-Content -Path $rootNpmrc -Value $npmrcContent -NoNewline
32+
Write-Host "Created $rootNpmrc"
33+
34+
# Overwrite Rush .npmrc to use private feed for rush install
35+
$rushNpmrc = Join-Path $SourcesDirectory "autorest.powershell/common/config/rush/.npmrc"
36+
Set-Content -Path $rushNpmrc -Value $npmrcContent -NoNewline
37+
Write-Host "Updated $rushNpmrc"

0 commit comments

Comments
 (0)