Aracılığıyla paylaş


Set up your project and connect to Azure Artifacts

TFS 2018

Azure Artifacts enables you to publish various package types to your feeds and install packages from both feeds and public registries like npmjs.com. Before we can authenticate with Azure Artifacts, we need to configure our .npmrc file, which stores the feed URLs and credentials that Npm uses. This file can be used to customize the behavior of the Npm client, such as setting up proxies, specifying default package locations, or configuring private package feeds. The .npmrc file is located in the user's home directory and can also be created at the project level to override the default settings. By editing the .npmrc file, users can customize their Npm experience and make it more tailored to their needs.

Project setup

For best practice, we suggest using two separate configuration files. The first file is used to authenticate with Azure Artifacts, while the second file is stored locally and contains your credentials. To set up the second file, place it in your home directory on your development machine and include all of your registry credentials. By using this approach, the Npm client can easily retrieve your credentials for authentication, allowing you to share your configuration file while keeping your credentials secure. These steps will walk you through the process of setting up the first configuration file:

  1. Select Build and Release.

  2. Select Packages, and then select Connect to feed.

    Screenshot showing how to connect to a feed in TFS.

  3. Select npm from the left navigation pane.

  4. Follow the instructions provided in the Other tab to set up your project.

Tip

Using multiple registries in .npmrc files is supported with scopes and upstream sources.

Note

vsts-npm-auth is not supported in TFS and Azure DevOps Server.

Pipeline authentication

For authentication with your pipeline, Azure Artifacts recommends using the npm authenticate task. When using a task runner like gulp or Grunt, it's important to add the npm authenticate task to the beginning of your pipeline. By doing so, your credentials are injected into your project's .npmrc file and persisted during the pipeline run, enabling subsequent steps to use the credentials in the configuration file.

  1. Select Build and Release, and then select Builds.

    Screenshot showing how to access your builds in TFS.

  2. Select your pipeline, and then select Edit.

  3. Select + to add a task to your pipeline.

    Screenshot showing how to add a new task to your pipeline.

  4. Search for the npm Authenticate task, and then select Add to add it to your pipeline.

    Screenshot showing the npm authenticate task.

  5. Select your .npmrc file.

    Screenshot showing how to add your .npmrc file to the npm authenticate task.

  6. Select Save & queue when you're done.

Note

To grant your pipeline access to your feed, make sure you set the build service role to Contributor in your feed settings.

A screenshot showing the build service roles in feed settings.

Note

If your organization is using a firewall or a proxy server, make sure you allow the appropriate domain URLs. For more information, please refer to the list of Allowed IP addresses and domain URLs.

Troubleshoot

vsts-npm-auth is not recognized

If you encounter the following error while running your project:

  • Cmd: 'vsts-npm-auth' is not recognized as an internal or external command, operable program or batch file.
  • PowerShell: vsts-npm-auth : The term 'vsts-npm-auth' is not recognized as the name of a cmdlet, function, script file, or operable program.

Then it's likely that the npm modules folder is not added to your path. To resolve this issue, rerun the Node.js setup and make sure to select the Add to PATH option.

A Screenshot showing how to set up node.js.

As an alternative solution, you can add the npm modules folder to your path by editing the PATH variable %APPDATA%\npm in Command Prompt or $env:APPDATA\npm in PowerShell.

Unable to authenticate

If you're running into a E401 error: code E401 npm ERR! Unable to authenticate. Run the vsts-npm-auth command with -F flag to reauthenticate.

vsts-npm-auth -config .npmrc -F
Reset vsts-npm-auth

Follow the steps below to modify/reset your vsts-npm-auth credentials:

  • Uninstall vsts-npm-auth.

    npm uninstall -g vsts-npm-auth
    
  • Clear your npm cache.

    npm cache clean --force
    
  • Delete your .npmrc file.

  • Reinstall vsts-npm-auth.

    npm install -g vsts-npm-auth --registry https://registry.npmjs.com --always-auth false