ARTIFACTORY: Using NPM client 9 with Jenkins Artifactory Plugins

AuthorFullName__c
Shisiya Sebastian
articleNumber
000005778
FirstPublishedDate
2023-06-11T10:53:15Z
lastModifiedDate
2025-07-22

ARTIFACTORY: Using NPM client 9 with Jenkins Artifactory Plugins

The Artifactory plugins can be used for a variety of packages supported by Artifactory. Here, we see how to resolve an issue with NPM package installation while using NPM9 client and Artifactory plugin in Jenkins.

The ERR_INVALID_AUTH error with NPM9

While trying to install an NPM package using the Jenkins Pipeline and Artifactory Jenkins plugin, an error is encountered. Here, the NPM version 9.5.0 and error is as given below.

npm ERR! code ERR_INVALID_AUTH
npm ERR! Invalid auth configuration found: `_auth` must be renamed to `//artifactory_host/artifactory/api/npm/:_auth` in project config
npm ERR! Please run `npm config fix` to repair your configuration.`


Though we try ‘npm config fix’ it won’t fix the error as the configuration is automatically generated by the Artifactory Plugin using JFrog CLI which cannot be changed.

Solution

If you are using NPM version 9 or the latest, you will face the above issue which is due to changes in the NPM authentication configuration implemented since v8.19. This functionality is implemented in JFrog CLI v2 which is used by the new Jenkins JFrog plugin. You can use this plugin to resolve the issue. To find the difference between both plugins, please scroll down below.

You can refer to the sample Pipeline script below to test the solution:

pipeline {
    agent any
    tools {
        jfrog 'jfrog-cli'
    }
    stages {
        stage('Clone') {
            steps {
                git branch: 'master', url: "https://github.com/jfrog/project-examples.git"
            }
        }

        stage('Exec npm commands') {
            steps {
                dir('npm-example') {
                    // Configure npm project's repositories
                    jf 'npm-config --repo-resolve testpipe-npm --repo-deploy testpipe-npm'

                    // Install dependencies
                    jf 'npm install'

                    // Pack and deploy the npm package
                    jf 'npm publish'
                }
            }
        }

        stage('Publish build info') {
            steps {
                jf 'rt build-publish'
            }
        }
    }
}


Output Snippet from pipeline:

[npm-example] $ /var/lib/jenkins/tools/io.jenkins.plugins.jfrog.JfrogInstallation/jfrog-cli/jf npm-config --repo-resolve testpipe-npm --repo-deploy testpipe-npm
06:43:11 [Info] npm build config successfully created.
[Pipeline] jf
[npm-example] $ /var/lib/jenkins/tools/io.jenkins.plugins.jfrog.JfrogInstallation/jfrog-cli/jf npm install
06:43:13 [Info] Running 'npm install ' command.
up to date, audited 20 packages in 2s

found 0 vulnerabilities
06:43:17 [Info] npm install finished successfully.
[Pipeline] jf
[npm-example] $ /var/lib/jenkins/tools/io.jenkins.plugins.jfrog.JfrogInstallation/jfrog-cli/jf npm publish
06:43:17 [Info] Running npm Publish
npm notice 
npm notice 📦  npm-example@0.0.3
npm notice === Tarball Contents === 
npm notice 125B  .jfrog/projects/npm.yaml
npm notice 2.9kB README.md               
npm notice 181B  helloworld.js           
npm notice 1.5kB npm-example-0.0.3.tgz   
npm notice 198B  package.json            
npm notice === Tarball Details === 
npm notice name:          npm-example                             
npm notice version:       0.0.3                                   
npm notice filename:      npm-example-0.0.3.tgz                   
npm notice package size:  3.5 kB                                  
npm notice unpacked size: 5.0 kB                                  
npm notice shasum:        135e3d0cc8271dfb53ef960571ce270c413ce2e0
npm notice integrity:     sha512-Hgphdv0L8pEWx[...]pN1HhY/9CPkaA==
npm notice total files:   5                                       
npm notice 
06:43:18 [Info] [Thread 2] Uploading: /var/lib/jenkins/workspace/npmnew/npm-example/npm-example-0.0.3.tgz
06:43:19 [Info] npm publish finished successfully.
{
  "status": "success",
  "totals": {
    "success": 0,
    "failure": 0
  }
}
The difference in the Jenkins Artifactory and JFrog plugins

The Jenkins Artifactory plugin integrates Jenkins and Artifactory to publish, resolve, promote, and release traceable build artifacts.
The Jenkins JFrog Plugin is an advanced solution that seamlessly integrates with the Jenkins Artifactory plugin, enabling parallel installation and usage. With the Jenkins JFrog Plugin, users can effortlessly connect Jenkins with the JFrog Platform, leveraging the capabilities of JFrog CLI through the plugin. It allows for the execution of any JFrog CLI command directly from within Jenkins Pipeline jobs.

If you are currently utilizing the Artifactory Plugin, we highly recommend installing the Jenkins JFrog Plugin alongside it and gradually migrating your jobs to the new plugin. You also have the option to continue using both plugins in your existing jobs. While the old plugin will continue to be supported, new features and functionality will predominantly be introduced in the new plugin. By adopting the Jenkins JFrog Plugin, you can take advantage of the latest enhancements and advancements in the integration between Jenkins and JFrog Platform.
 

References:

https://plugins.jenkins.io/jfrog/
https://plugins.jenkins.io/artifactory/
​​​​​​​https://jfrog.com/help/r/jfrog-integrations-documentation/jenkins-artifactory-plug-in