Hello everyone! I need some guidance on publishing my NPM package to Nexus using a Jenkins pipeline. I’ve successfully done this with Maven projects before, but I’m struggling with the NPM setup.
Hit the same problem migrating from Artifactory to Nexus last year. With NPM packages, you’ve got to run npm pack first to create the .tgz file - don’t try npm publish directly to Nexus through Jenkins. For file path, use dist/${packageName}-${version}.tgz where the tgz gets created after npm pack. GroupId’s weird with NPM since it doesn’t follow Maven rules - I just use the scope from package.json or the package name if there’s no scope. Authentication bit me hard. Your .npmrc needs to be set up in the Jenkins workspace before nexusArtifactUploader runs. I had to add a step that generates the .npmrc with Nexus registry URL and auth token, otherwise uploads fail without any error message. Also check that your Nexus npm-repository actually accepts uploads and isn’t just proxying public registries.
Been there! npm pack is def the way to go - it creates the .tgz file Nexus expects. For the file path, just use *.tgz or grab it dynamically with ls *.tgz. GroupId’s tricky with npm packages. I usually just put the package name there since npm doesn’t use Maven-style grouping anyways.
Struggled with this same setup for months before cracking it. You need npm pack before nexusArtifactUploader - that’s what creates the tarball Nexus wants. The tricky bit is nailing the file path after packing. I run a shell command to grab npm pack’s output (it spits out the exact filename) and dump it into an env variable for the uploader. For groupId with NPM packages - use the package scope if you’ve got one (@mycompany for scoped packages) or just stick with the package name for unscoped. Version needs to match package.json exactly. Here’s what bit me: make sure your Jenkins agent’s NPM registry config points to Nexus. Without that, uploads might work but won’t appear where you’d expect in the repo browser.