From 5dbd815047af61bae5209ae157555e864cd80b82 Mon Sep 17 00:00:00 2001 From: Chidozie Ononiwu Date: Thu, 18 Jun 2026 18:22:44 -0700 Subject: [PATCH 1/2] Use authenticated npmrc --- eng/test-steps.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/eng/test-steps.yml b/eng/test-steps.yml index eba27ca6..78804365 100644 --- a/eng/test-steps.yml +++ b/eng/test-steps.yml @@ -7,8 +7,13 @@ steps: - task: UseDotNet@2 inputs: version: 6.x + - template: /eng/common/pipelines/templates/steps/create-authenticated-npmrc.yml + parameters: + npmrcPath: $(Agent.TempDirectory)/test/.npmrc - script: npm ci displayName: npm ci + env: + npm_config_userconfig: "$(Agent.TempDirectory)/test/.npmrc" - script: npm run lint displayName: lint - script: npm run prettier From 638d65eda9c6f714085f7fa4c9b2c524f8f1c66a Mon Sep 17 00:00:00 2001 From: Chidozie Ononiwu Date: Fri, 19 Jun 2026 11:09:02 -0700 Subject: [PATCH 2/2] Add eng/common directory --- .../steps/create-authenticated-npmrc.yml | 41 +++++++++++++++++++ eng/test-steps.yml | 4 -- 2 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 eng/common/pipelines/templates/steps/create-authenticated-npmrc.yml diff --git a/eng/common/pipelines/templates/steps/create-authenticated-npmrc.yml b/eng/common/pipelines/templates/steps/create-authenticated-npmrc.yml new file mode 100644 index 00000000..3fa699b3 --- /dev/null +++ b/eng/common/pipelines/templates/steps/create-authenticated-npmrc.yml @@ -0,0 +1,41 @@ +parameters: + - name: npmrcPath + type: string + # When empty, defaults to the agent user's .npmrc ($HOME/.npmrc on + # Linux/macOS, %USERPROFILE%\.npmrc on Windows) so every subsequent + # npm / pnpm / npx call in the job inherits the registry + auth. + default: "" + - name: registryUrl + type: string + default: "https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-js/npm/registry/" + - name: CustomCondition + type: string + default: succeeded() + - name: ServiceConnection + type: string + default: "" + +steps: + - pwsh: | + $npmrcPath = '${{ parameters.npmrcPath }}' + if (-not $npmrcPath) { $npmrcPath = Join-Path $HOME '.npmrc' } + + Write-Host "Creating .npmrc file $npmrcPath for registry ${{ parameters.registryUrl }}" + $parentFolder = Split-Path -Path $npmrcPath -Parent + + if ($parentFolder -and -not (Test-Path $parentFolder)) { + Write-Host "Creating folder $parentFolder" + New-Item -Path $parentFolder -ItemType Directory | Out-Null + } + + "registry=${{ parameters.registryUrl }}" | Out-File $npmrcPath + Write-Host "##vso[task.setvariable variable=resolvedNpmrcPath]$npmrcPath" + displayName: "Create .npmrc" + condition: ${{ parameters.CustomCondition }} + + - task: npmAuthenticate@0 + displayName: Authenticate .npmrc + condition: ${{ parameters.CustomCondition }} + inputs: + workingFile: $(resolvedNpmrcPath) + azureDevOpsServiceConnection: ${{ parameters.ServiceConnection }} diff --git a/eng/test-steps.yml b/eng/test-steps.yml index 78804365..3303d073 100644 --- a/eng/test-steps.yml +++ b/eng/test-steps.yml @@ -8,12 +8,8 @@ steps: inputs: version: 6.x - template: /eng/common/pipelines/templates/steps/create-authenticated-npmrc.yml - parameters: - npmrcPath: $(Agent.TempDirectory)/test/.npmrc - script: npm ci displayName: npm ci - env: - npm_config_userconfig: "$(Agent.TempDirectory)/test/.npmrc" - script: npm run lint displayName: lint - script: npm run prettier