|
1 | 1 | parameters: |
2 | 2 | - name: npmrcPath |
3 | 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: "" |
4 | 8 | - name: registryUrl |
5 | 9 | 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/" |
7 | 11 | - name: CustomCondition |
8 | 12 | type: string |
9 | 13 | default: succeeded() |
10 | 14 | - name: ServiceConnection |
11 | 15 | type: string |
12 | | - default: '' |
| 16 | + default: "" |
13 | 17 |
|
14 | 18 | 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' } |
23 | 22 |
|
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 |
28 | 25 |
|
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