Skip to content

Commit 8d56ab0

Browse files
Update create-authenticated-npmrc to default npmrcpath to User npmrc path (#47599)
Co-authored-by: Chidozie Ononiwu <chononiw@microsoft.com>
1 parent 950c503 commit 8d56ab0

1 file changed

Lines changed: 27 additions & 20 deletions

File tree

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,41 @@
11
parameters:
22
- name: npmrcPath
33
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: ""
48
- name: registryUrl
59
type: string
6-
default: 'https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-js/npm/registry/'
10+
default: "https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-js/npm/registry/"
711
- name: CustomCondition
812
type: string
913
default: succeeded()
1014
- name: ServiceConnection
1115
type: string
12-
default: ''
16+
default: ""
1317

1418
steps:
15-
- pwsh: |
16-
Write-Host "Creating .npmrc file ${{ parameters.npmrcPath }} for registry ${{ parameters.registryUrl }}"
17-
$parentFolder = Split-Path -Path '${{ parameters.npmrcPath }}' -Parent
18-
19-
if (!(Test-Path $parentFolder)) {
20-
Write-Host "Creating folder $parentFolder"
21-
New-Item -Path $parentFolder -ItemType Directory | Out-Null
22-
}
19+
- pwsh: |
20+
$npmrcPath = '${{ parameters.npmrcPath }}'
21+
if (-not $npmrcPath) { $npmrcPath = Join-Path $HOME '.npmrc' }
2322
24-
$content = "registry=${{ parameters.registryUrl }}"
25-
$content | Out-File '${{ parameters.npmrcPath }}'
26-
displayName: 'Create .npmrc'
27-
condition: ${{ parameters.CustomCondition }}
23+
Write-Host "Creating .npmrc file $npmrcPath for registry ${{ parameters.registryUrl }}"
24+
$parentFolder = Split-Path -Path $npmrcPath -Parent
2825
29-
- task: npmAuthenticate@0
30-
displayName: Authenticate .npmrc
31-
condition: ${{ parameters.CustomCondition }}
32-
inputs:
33-
workingFile: ${{ parameters.npmrcPath }}
34-
azureDevOpsServiceConnection: ${{ parameters.ServiceConnection }}
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 }}

0 commit comments

Comments
 (0)