Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion .azure-pipelines/common-templates/install-tools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,25 @@ steps:
displayName: Install NodeJs
inputs:
versionSpec: 18.x


- task: PowerShell@2
displayName: Configure private npm feed
inputs:
targetType: filePath
pwsh: true
filePath: $(Build.SourcesDirectory)/tools/Configure-PrivateNpmFeed.ps1
arguments: -SourcesDirectory "$(Build.SourcesDirectory)"

- task: npmAuthenticate@0
displayName: Authenticate to private npm feed
inputs:
workingFile: $(Build.SourcesDirectory)/.npmrc

- task: npmAuthenticate@0
displayName: Authenticate to private npm feed (Rush)
inputs:
workingFile: $(Build.SourcesDirectory)/autorest.powershell/common/config/rush/.npmrc

- task: Npm@1
displayName: Install AutoRest
inputs:
Expand Down
37 changes: 37 additions & 0 deletions tools/Configure-PrivateNpmFeed.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

<#
.SYNOPSIS
Configures .npmrc files to use a private Azure Artifacts npm feed.

.DESCRIPTION
Creates .npmrc files at the repository root and in the Rush config directory
to redirect npm and Rush package installations to a private feed. This is
used in CI pipelines where network isolation rules block the public npm registry.

.PARAMETER SourcesDirectory
The root directory of the repository. Defaults to the current directory.

.PARAMETER Registry
The private npm registry URL.
#>
param(
[Parameter()]
[string]$SourcesDirectory = (Get-Location).Path,

[Parameter()]
[string]$Registry = "https://microsoftgraph.pkgs.visualstudio.com/0985d294-5762-4bc2-a565-161ef349ca3e/_packaging/PowerShell_V2_Build/npm/registry/"
)

$npmrcContent = "registry=$Registry`nalways-auth=true"

# Create .npmrc at repo root for global npm installs (autorest, rush)
$rootNpmrc = Join-Path $SourcesDirectory ".npmrc"
Set-Content -Path $rootNpmrc -Value $npmrcContent -NoNewline
Write-Host "Created $rootNpmrc"

# Overwrite Rush .npmrc to use private feed for rush install
$rushNpmrc = Join-Path $SourcesDirectory "autorest.powershell/common/config/rush/.npmrc"
Set-Content -Path $rushNpmrc -Value $npmrcContent -NoNewline
Write-Host "Updated $rushNpmrc"
Loading