Search code examples
node.jsjenkinsnpmjenkins-pipelinelerna

Lerna publish using jenkins pipeline


I've been going through the nightmare that is trying to get lerna to publish in my ci pipeline.

I've managed to have the scripts pull from git to check tags and I've found the withNPM pipeline plugin. Because I'm using lerna to publish multiple packages I have to move the .npmrc file that the plugin creates in the workspace to the root of the the home directory so that all packages can access it.

The NPM plugin uses the jenkins config file to create the .npmrc file. Which looks like this:

//registry.npmjs.com/:_authToken=TOKEN

Here is what I have in my Jenkins pipeline.

stage('lerna publish') {
    steps {
        withCredentials([sshUserPrivateKey(credentialsId: 'cb8acd82-3a50-4a94-9d5f-44b04856e6fd', keyFileVariable: 'GITHUB_KEY')]) {
            sh 'echo ssh -i $GITHUB_KEY -l git -o StrictHostKeyChecking=no \\"\\$@\\" > ./run_ssh.sh'
            sh 'chmod +x ./run_ssh.sh'
            withEnv(['GIT_SSH=./run_ssh.sh']) {
                withNPM(npmrcConfig: 'da4e5199-b04b-41b6-a03f-dfbcc344f701') {
                    sh "rm -rf ~/.npmrc"
                    sh 'mv ./.npmrc ~/.npmrc'
                    sh 'npm config set registry https://registry.npmjs.com/'
                    sh 'git config --global user.email "thomas@reggi.com"'
                    sh 'git config --global user.name "reggi"'
                    sh 'git checkout master'
                    sh 'git pull origin master --force'
                    sh 'npm run lerna-publish'
                }
            }
        }
    }
}

Here's the error:

lerna info auto-confirmed 
lerna info publish Publishing packages to npm...
lerna ERR! npm publish --ignore-scripts exited 1 in '@reggi/help.filter-until'
lerna ERR! npm publish --ignore-scripts stderr:
npm notice 
npm notice package: @reggi/help.filter-until@0.0.20
npm notice === Tarball Contents === 
npm notice 1.5kB package.json  
npm notice 609B  index.build.js
npm notice === Tarball Details === 
npm notice name:          @reggi/help.filter-until                
npm notice version:       0.0.20                                  
npm notice package size:  997 B                                   
npm notice unpacked size: 2.1 kB                                  
npm notice shasum:        a6db6d4dc02f05548c22fe2e034832ac02252633
npm notice integrity:     sha512-6oAFaXqZMREsh[...]GnMcnIxXUBINg==
npm notice total files:   2                                       
npm notice 
npm ERR! code ENEEDAUTH
npm ERR! need auth auth required for publishing
npm ERR! need auth You need to authorize this machine using `npm adduser`

I found I wasn't being consistent with the urls above and changed them both to .com and now I'm getting this issue:

lerna info auto-confirmed 
lerna info publish Publishing packages to npm...
lerna ERR! npm publish --ignore-scripts exited 1 in '@reggi/help.filter-until'
lerna ERR! npm publish --ignore-scripts stderr:
npm notice 
npm notice package: @reggi/help.filter-until@0.0.23
npm notice === Tarball Contents === 
npm notice 1.5kB package.json  
npm notice 609B  index.build.js
npm notice === Tarball Details === 
npm notice name:          @reggi/help.filter-until                
npm notice version:       0.0.23                                  
npm notice package size:  1.0 kB                                  
npm notice unpacked size: 2.1 kB                                  
npm notice shasum:        60ee325b219abdae06a75cfe45bc66096f715187
npm notice integrity:     sha512-o4ahyOWAsUk3j[...]O/3MH2Tpv1tOQ==
npm notice total files:   2                                       
npm notice 
npm ERR! publish Failed PUT 404
npm ERR! code E404
npm ERR! 404 Not found : @reggi/help.filter-until
npm ERR! 404 
npm ERR! 404  '@reggi/help.filter-until' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404 
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.

Solution

  • I have the token setting using the .org domain and the registry set to the .com domain. :(