Now (2023) this can be done by adding the proper service connection, and authenticating via npmAuthenticate@0
.
Create Service Connection
In order to create the proper service connection in Azure Devops you have to
- open project settings from the gear icon
- open service connections under pipelines
- click on New Service Connection
- select NPM
- choose Authentication token
- paste in Registry URL:
https://npm.fontawesome.com/
- paste in Personal Access Token your token
- set
Fontawesome
as Service connection name. Note that this is the identifier of the connection and it is used by Azure
- check the Grant access permission to all pipelines in case you want all the pipelines of your project to have access to it
- save
The window should be like this:

You can read more about the procedure at Learn.
Authenticate in the Pipeline
The authentication is done by the npmAuthenticate@0
provided that your .npmrc
already includes the proper registry configuration, which at this time, happens to be @fortawesome:registry=https://npm.fontawesome.com/
In this case, the pipeline would be something like this:
steps:
- task: npmAuthenticate@0
displayName: "Authenticate NPM registry"
inputs:
workingFile: .npmrc
customEndpoint: Fontawesome
Note that CustomEndpoint here refers to the name entered previously in Service connection name.
Bonus
We don't use explicit .npmrc
files in our builds, for this reason, we manually forge the configuration at runtime. Note that we build on self-hosted agents in containers, therefore we have a brand new throw-away environment every time, and leaving the environment in a dirty state is not a problem in this case.
steps:
- task: PowerShell@2
displayName: "Prepare NPM authentication"
inputs:
targetType: "inline"
script: |
$registry = '$(COMPANY_DEVOPS_REGISTRY)'
npm config set 'registry' "$registry"
npm config set '@fortawesome:registry' 'https://npm.fontawesome.com/'
$fileName = [IO.Path]::Combine($home, '.npmrc')
if (!(Test-Path -Path $fileName)) {
Write-Host "##vso[task.logissue type=error;]Could not find the proper npm configuration file."
Write-Host "##vso[task.complete result=Failed;]"
exit 0
}
Write-Host "##vso[task.setvariable variable=npmrcFilePath]$filename"
- task: npmAuthenticate@0
displayName: "Authenticate NPM registry"
inputs:
workingFile: $(npmrcFilePath)
customEndpoint: Fontawesome
Above, COMPANY_DEVOPS_REGISTRY
is a variable containing our NPM Azure Devops registry. The first task ensures we have all the necessary information stored in the configuration file, which we know to be located in the home folder of the current user.
The second task, simply authenticates using the global configuration file.