Skip to content

Commit fbfea92

Browse files
Use authenticated npmrc (#488)
* Use authenticated npmrc * Add eng/common directory
1 parent ffe7038 commit fbfea92

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
parameters:
2+
- name: npmrcPath
3+
type: string
4+
# When empty, defaults to the agent user's .npmrc ($HOME/.npmrc on
5+
# Linux/macOS, %USERPROFILE%\.npmrc on Windows) so every subsequent
6+
# npm / pnpm / npx call in the job inherits the registry + auth.
7+
default: ""
8+
- name: registryUrl
9+
type: string
10+
default: "https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-js/npm/registry/"
11+
- name: CustomCondition
12+
type: string
13+
default: succeeded()
14+
- name: ServiceConnection
15+
type: string
16+
default: ""
17+
18+
steps:
19+
- pwsh: |
20+
$npmrcPath = '${{ parameters.npmrcPath }}'
21+
if (-not $npmrcPath) { $npmrcPath = Join-Path $HOME '.npmrc' }
22+
23+
Write-Host "Creating .npmrc file $npmrcPath for registry ${{ parameters.registryUrl }}"
24+
$parentFolder = Split-Path -Path $npmrcPath -Parent
25+
26+
if ($parentFolder -and -not (Test-Path $parentFolder)) {
27+
Write-Host "Creating folder $parentFolder"
28+
New-Item -Path $parentFolder -ItemType Directory | Out-Null
29+
}
30+
31+
"registry=${{ parameters.registryUrl }}" | Out-File $npmrcPath
32+
Write-Host "##vso[task.setvariable variable=resolvedNpmrcPath]$npmrcPath"
33+
displayName: "Create .npmrc"
34+
condition: ${{ parameters.CustomCondition }}
35+
36+
- task: npmAuthenticate@0
37+
displayName: Authenticate .npmrc
38+
condition: ${{ parameters.CustomCondition }}
39+
inputs:
40+
workingFile: $(resolvedNpmrcPath)
41+
azureDevOpsServiceConnection: ${{ parameters.ServiceConnection }}

eng/test-steps.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ steps:
77
- task: UseDotNet@2
88
inputs:
99
version: 6.x
10+
- template: /eng/common/pipelines/templates/steps/create-authenticated-npmrc.yml
1011
- script: npm ci
1112
displayName: npm ci
1213
- script: npm run lint

0 commit comments

Comments
 (0)