Quantcast
Channel: Active questions tagged feed - Stack Overflow
Viewing all articles
Browse latest Browse all 547

How to publish Angular Libraries in Azure DevOps Artifacts feed?

$
0
0

I am trying to publish some Angular Libraries in an Azure DevOps Artifacts feed using an Azure Pipeline yaml, but i have a problem with authentication.

I implemented two solutions but both don't work.

Using .npmrc file

As suggested in feed section, i created the .npmrc file:

registry=https://pkgs.dev.azure.com/ORGANIZATION/PROJECT/_packaging/FEED/npm/registry/always-auth=true

Then i created the following yaml:

trigger:  batch: true # disable concurrent build for pipeline  branches:    include:      - mainpool:  vmImage: 'windows-latest'stages:  - stage: Publish    displayName: 'Publish Stage'    jobs:      - job: execute_publish        displayName: 'Publish Job'        steps:          - task: NodeTool@0            inputs:              versionSpec: '18.13.x'            displayName: 'Install node.js'          - task: NpmAuthenticate@0            inputs:              workingFile: '.npmrc'            displayName: 'Authenticate with Azure DevOps NPM feed'          - script: |              npm install            displayName: 'Install dependencies'          - script: |              npm run test            displayName: 'Execute tests'          - script: |              npm run publish:LIBRARY            displayName: 'Publish LIBRARY'

Where the npm run publish:LIBRARY is a script in the package.json

"publish:LIBRARY": "cd ./projects/LIBRARY && npm version patch && ng build && cd ../../dist/LIBRARY && npm publish",

All commands in a local environment work, but the pipeline fails:

npm ERR! code ETARGETnpm ERR! notarget No matching version found for RANDOM-PACKAGE.npm ERR! notarget In most cases you or one of your dependencies are requestingnpm ERR! notarget a package version that doesn't exist.

Split in two stages

As a second solution, i try to split build and publish in two different stages.

Without using .npmrc file, this was the yaml:

trigger:  batch: true # disable concurrent build for pipeline  branches:    include:      - '*'  # CI start for all branchespool:  vmImage: 'windows-latest'stages:  - stage: Build    displayName: 'Build Stage'    condition: eq(variables['build.sourceBranch'], 'refs/heads/main')    jobs:      - job: execute_build        displayName: 'Build Job'        steps:          - task: NodeTool@0            inputs:              versionSpec: '18.13.x'            displayName: 'Install node.js'          - script: |              npm config set registry=https://registry.npmjs.org/            displayName: 'Set public registry'          - script: |              npm install            displayName: 'Install dependencies'          - script: |              npm run test            displayName: 'Execute tests'          - script: |              npm run build:LIBRARY            displayName: 'Build LIBRARY'  - stage: Publish    displayName: 'Publish Stage'    dependsOn: Build    jobs:      - job: execute_publish        displayName: 'Publish Job'        steps:          - task: NodeTool@0            inputs:              versionSpec: '18.13.x'            displayName: 'Install node.js'          - script: |              echo "registry=https://pkgs.dev.azure.com/ORGANIZATION/PROJECT/_packaging/FEED/npm/registry/" > .npmrc              echo "always-auth=true" >> .npmrc            displayName: 'Cerate .npmrc file'          - task: NpmAuthenticate@0            inputs:              workingFile: '.npmrc'            displayName: 'Authenticate with Azure DevOps NPM feed'          - script: |              cd $(System.DefaultWorkingDirectory)/dist/LIBRARY/              npm publish            displayName: 'Publish LIBRARY'          - script: rm .npmrc            displayName: 'Remove .npmrc file'

Where the npm run build:LIBRARY is a script in the package.json:

"publish:LIBRARY": "cd ./projects/LIBRARY && npm version patch && ng build && cd ../../dist/LIBRARY && npm pack",

Build Stage succeded, but Publish Stage fails:

npm ERR! code ENEEDAUTHnpm ERR! need auth This command requires you to be logged in to https://pkgs.dev.azure.com/Jakala/DataAlliance/_packaging/frontend-feed/npm/registry/:_authToken=fyvsmbutef7ot2n275hfgq3hcih2dinn3scrbvd6osvovb2ozfsanpm ERR! need auth You need to authorize this machine using `npm adduser`

what is the correct way to implement this publication task?

Thank You


Viewing all articles
Browse latest Browse all 547

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>