I need to create a jenkins job for publishing a package to npmjs.com. The package source code is in a github repository.
I successfully publish the package from my pc executing 'npm publish' command in console but facing an error using jenkins.
That is what i have in my jenkins job:
Specified path to the github project.
Added 'Execute Windows batch command'. The script:
git checkout master
git pull
npm publish
The console output:
C:\Program Files (x86)\Jenkins\workspace\js-agent-cucumber-release>git checkout master
Your branch is behind 'origin/master' by 2 commits, and can be fast-forwarded.
(use "git pull" to update your local branch)
Previous HEAD position was fbd7040 Update package.json
Switched to branch 'master'
C:\Program Files (x86)\Jenkins\workspace\js-agent-cucumber-release>git pull
Updating 27de403..fbd7040
Fast-forward
package.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
C:\Program Files (x86)\Jenkins\workspace\js-agent-cucumber-release>npm publish
npm notice
npm notice package: reportportal-agent-cucumber#2.0.5
npm notice === Tarball Contents ===
npm notice 1.4kB package.json
npm notice 49B .eslintrc.js
npm notice 11.6kB LICENSE
npm notice 11.3kB README.md
npm notice 15.6kB modules/cucumber-epam-reportportal-handler.js
npm notice 191B modules/index.js
npm notice 1.3kB modules/loggerWorld.js
npm notice 267B testSample/config/rpConfig.json
npm notice 1.4kB testSample/cuceLaunch.js
npm notice 234B testSample/features/noStepDef.feature
npm notice 222B testSample/features/passed.feature
npm notice 285B testSample/features/scenarioOutline.feature
npm notice 362B testSample/features/step_definitions/support/handlers.js
npm notice 139B testSample/features/step_definitions/support/hooks.js
npm notice 748B testSample/features/step_definitions/support/world.js
npm notice 2.5kB testSample/features/step_definitions/waiting.js
npm notice 340B testSample/features/table.feature
npm notice 374B testSample/features/webDriverFailed.feature
npm notice 327B testSample/package.json
npm notice 820B testSample/protractor.conf.js
npm notice 291B testSample/protractor/features/failedProtractor.feature
npm notice 184B testSample/protractor/features/noSuchElementProtractor.feature
npm notice 217B testSample/protractor/features/protractor.feature
npm notice 954B testSample/protractor/features/step_definitions/protractorSteps.js
npm notice 368B testSample/protractor/features/step_definitions/support/handlers.js
npm notice 136B testSample/protractor/features/step_definitions/support/hooks.js
npm notice 216B testSample/protractor/features/step_definitions/support/world.js
npm notice 6B testSample/reports/report.json
npm notice === Tarball Details ===
npm notice name: reportportal-agent-cucumber
npm notice version: 2.0.5
npm notice package size: 15.3 kB
npm notice unpacked size: 51.9 kB
npm notice shasum: 478e6712549cfd3b0d472091409ef248625aa2e1
npm notice integrity: sha512-NpE2GRG6a9YV7[...]DdxhC8MtZbISA==
npm notice total files: 28
npm notice
npm ERR! path C:\WINDOWS\TEMP\npm-9528-4708d294\tmp\fromDir-47da48b4\package.tgz
npm ERR! code EPERM
npm ERR! errno -4048
npm ERR! syscall unlink
npm ERR! Error: EPERM: operation not permitted, unlink 'C:\WINDOWS\TEMP\npm-9528-4708d294\tmp\fromDir-47da48b4\package.tgz'
npm ERR! { [Error: EPERM: operation not permitted, unlink 'C:\WINDOWS\TEMP\npm-9528-4708d294\tmp\fromDir-47da48b4\package.tgz']
npm ERR! cause:
npm ERR! { Error: EPERM: operation not permitted, unlink 'C:\WINDOWS\TEMP\npm-9528-4708d294\tmp\fromDir-47da48b4\package.tgz'
npm ERR! errno: -4048,
npm ERR! code: 'EPERM',
npm ERR! syscall: 'unlink',
npm ERR! path:
npm ERR! 'C:\\WINDOWS\\TEMP\\npm-9528-4708d294\\tmp\\fromDir-47da48b4\\package.tgz' },
npm ERR! isOperational: true,
npm ERR! stack:
npm ERR! 'Error: EPERM: operation not permitted, unlink \'C:\\WINDOWS\\TEMP\\npm-9528-4708d294\\tmp\\fromDir-47da48b4\\package.tgz\'',
npm ERR! errno: -4048,
npm ERR! code: 'EPERM',
npm ERR! syscall: 'unlink',
npm ERR! path:
npm ERR! 'C:\\WINDOWS\\TEMP\\npm-9528-4708d294\\tmp\\fromDir-47da48b4\\package.tgz' }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It's possible that the file was already in use (by a text editor or antivirus),
npm ERR! or that you lack permissions to access it.
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator (though this is not recommended).
npm ERR! A complete log of this run can be found in:
npm ERR! C:\WINDOWS\system32\config\systemprofile\AppData\Roaming\npm-cache\_logs\2019-04-03T14_18_29_316Z-debug.log
Build step 'Execute Windows batch command' marked build as failure
Finished: FAILURE
Does any body know how to solve the problem ?
Finally I managed to create a pipeline for releasing my package to npmjs. Steps:
Create a jenkins job of the 'Pipeline' type.
In the section 'Pipeline' choose 'Pipeline script from SCM'.
Choose the repository type and add path to your repo.
Add a file called "Jenkinsfile" in the root of your project and put the below script into it.
pipeline {
agent {
docker {
image 'node:10-alpine'
args '-u root'
}
}
stages {
stage('Install') {
steps {
sh 'npm install'
}
}
stage('Publish') {
steps {
load "$JENKINS_HOME/jobvars.env"
withEnv(["TOKEN=${NPMJS_TOKEN}"]) {
sh 'echo "//registry.npmjs.org/:_authToken=${TOKEN}" >> ~/.npmrc'
sh 'npm publish'
}
}
}
}
}
Create a file called "jobvars.env" under the folder where the jenkins installed and
put the line into it:
NPMJS_TOKEN="token-generated-on-npmjs-com-in-your-profile"
Related
My user (shmue) is in the sudo group and for some reason create-react-app is not able to set up my boilerplate.
Here is the logs:
shmue#Edgar:/media/veracrypt1/Mega/Dev/JOBIFY$ npx create-react-app client
Creating a new React app in /media/veracrypt1/Mega/Dev/JOBIFY/client.
Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts with cra-template...
npm ERR! code EPERM
npm ERR! syscall symlink
npm ERR! path ../#babel/parser/bin/babel-parser.js
npm ERR! dest /media/veracrypt1/Mega/Dev/JOBIFY/client/node_modules/.bin/parser
npm ERR! errno -1
npm ERR! Error: EPERM: operation not permitted, symlink '../#babel/parser/bin/babel-parser.js' -> '/media/veracrypt1/Mega/Dev/JOBIFY/client/node_modules/.bin/parser'
npm ERR! [Error: EPERM: operation not permitted, symlink '../#babel/parser/bin/babel-parser.js' -> '/media/veracrypt1/Mega/Dev/JOBIFY/client/node_modules/.bin/parser'] {
npm ERR! errno: -1,
npm ERR! code: 'EPERM',
npm ERR! syscall: 'symlink',
npm ERR! path: '../#babel/parser/bin/babel-parser.js',
npm ERR! dest: '/media/veracrypt1/Mega/Dev/JOBIFY/client/node_modules/.bin/parser'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/shmue/.npm/_logs/2022-08-12T13_11_07_739Z-debug-0.log
Aborting installation.
npm install --no-audit --save --save-exact --loglevel error react react-dom react-scripts cra-template has failed.
Deleting generated file... package.json
Deleting client/ from /media/veracrypt1/Mega/Dev/JOBIFY
Done.
shmue#Edgar:/media/veracrypt1/Mega/Dev/JOBIFY$ sudo npx create-react-app client
[sudo] password for shmue:
sudo: npx: command not found
Please tell me how I can use CRA on ubuntu 20.
Thanks in advance.
Sam
I'm new in react-native, I'm trying to set up my project after all package install when I tried to start npm start command then show me 'expo-cli' is not recognized as an internal or external command, this error.
ok, then I have followed the guide from here
after that I have added my env path in this way:
environment variable > System Variables > PATH >
C:\Users\YOUR_USERNAME\AppData\Roaming\npm
then I have to install again:
npm install -g expo-cli
but it does not work for me, I don't know why.
when I try to run this command npm install -g expo-cli then show me an error like this:
PS C:\Users\alami\OneDrive\Desktop\React native\starter-react-native> npm install -g expo-cli
npm ERR! code EPERM
npm ERR! syscall mkdir
npm ERR! path C:\Program Files\nodejs\node_modules\expo-cli
npm ERR! errno -4048
npm ERR! Error: EPERM: operation not permitted, mkdir 'C:\Program Files\nodejs\node_modules\expo-cli'
npm ERR! [Error: EPERM: operation not permitted, mkdir 'C:\Program Files\nodejs\node_modules\expo-cli'] {
npm ERR! errno: -4048,
npm ERR! code: 'EPERM',
npm ERR! syscall: 'mkdir',
npm ERR! path: 'C:\\Program Files\\nodejs\\node_modules\\expo-cli'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It's possible that the file was already in use (by a text editor or antivirus),
npm ERR! or that you lack permissions to access it.
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\alami\AppData\Local\npm-cache\_logs\2021-05-21T00_58_34_585Z-debug.log
At least I just solved my problem in this way:
Search cmd
Then run as administrator
Then npm i -g expo-cli
I just solved my problem.
Even I tried the Set-execution policies to unrestricted which resolved my dummy serve error but can't create package.json.
OUTPUT is pasted below. Please note: I tried both npm init and npm init -y
PS C:\Windows\System32\WindowsPowerShell\v1.0> npm init -y
npm ERR! code EPERM
npm ERR! syscall open
npm ERR! path C:\Windows\System32\WindowsPowerShell\v1.0\package.json
npm ERR! errno -4048
npm ERR! Error: EPERM: operation not permitted, open 'C:\Windows\System32\WindowsPowerShell\v1.0\package.json'
npm ERR! [Error: EPERM: operation not permitted, open 'C:\Windows\System32\WindowsPowerShell\v1.0\package.json'] {
npm ERR! errno: -4048,
npm ERR! code: 'EPERM',
npm ERR! syscall: 'open',
npm ERR! path: 'C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\package.json'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It's possible that the file was already in use (by a text editor or antivirus),
npm ERR! or that you lack permissions to access it.
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\User\AppData\Roaming\npm-cache\_logs\2020-06-14T08_03_04_050Z-debug.log
You can't create a package.json because you are under C:\Windows\System32. Windows is stopping you from creating your own files where it keeps system files.
Change to another directory (prefereably one under C:\Users\YourUsernameHere\ and try again.
I am having permission problems with the npm config command. It seems that for some reason it is trying to change the owner of my ~/.npmrc file. When running npm config set color false, I get the following error:
npm ERR! Error: EPERM, chown '/home/bamboo/.npmrc'
npm ERR! { [Error: EPERM, chown '/home/bamboo/.npmrc'] errno: 50, code: 'EPERM', path: '/home/bamboo/.npmrc' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! System Linux 3.13.0-32-generic
npm ERR! command "/usr/bin/node" "/usr/bin/npm" "config" "set" "color" "false"
npm ERR! cwd /home/bamboo
npm ERR! node -v v0.10.33
npm ERR! npm -v 1.4.28
npm ERR! path /home/bamboo/.npmrc
npm ERR! code EPERM
npm ERR! errno 50
npm ERR! stack Error: EPERM, chown '/home/bamboo/.npmrc'
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/bamboo/npm-debug.log
npm ERR! not ok code 0
The file .npmrc has the right permissions and I can edit it manually but I need to do it from the npm config command since it is part of an automated build. I can't seem to find valuable information on that matter. I set the prefix to a directory I own and can install globally without any problem but can't run configure! I am running Ubuntu 14.04.
Does anybody have some ideas?
I had the same problem.
https://github.com/npm/npm/issues/7563
Turns out changing from sudo su to sudo su - when starting the bamboo agent process solved the problem.
Got this problem once.
The .npm directory does not have sufficient permissions. Run the following command:
sudo chown -R $(whoami) ~/.npm
I'm setting up a Meanjs instance with a Yeoman generator. When I do 'sudo yo meanjs' everything works fine until it looks like it is trying to make a directory and it fails, any ideas on what is going on here?
SOLINK_MODULE(target) Release/kerberos.node: Finished
> bson#0.2.5 install /Users/xxx/Documents/mean/node_modules/connect-
mongo/node_modules/mongodb/node_modules/bson
> (node-gyp rebuild 2> builderror.log) || (exit 0)
CXX(target) Release/obj.target/bson/ext/bson.o
SOLINK_MODULE(target) Release/bson.node
SOLINK_MODULE(target) Release/bson.node: Finished
npm ERR! Error: EACCES, mkdir '/Users/xxx/.npm/uglify-js/2.4.15'
npm ERR! { [Error: EACCES, mkdir '/Users/xxx/.npm/uglify-js/2.4.15']
npm ERR! errno: 3,
npm ERR! code: 'EACCES',
npm ERR! path: '/Users/xxx/.npm/uglify-js/2.4.15',
npm ERR! parent: 'grunt-contrib-uglify' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! System Darwin 13.4.0
npm ERR! command "node" "/usr/local/bin/npm" "install"
npm ERR! cwd /Users/xxx/Documents/mean
npm ERR! node -v v0.10.33
npm ERR! npm -v 1.4.28
npm ERR! path /Users/xxx/.npm/uglify-js/2.4.15
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! stack Error: EACCES, mkdir '/Users/xxx/.npm/uglify-js/2.4.15'
npm ERR! not ok code 0
That is a pretty common error.
Yeoman is running the following:
bower install & npm install
Bower install succeeded, however NPM install is failing because of user permissions. Just run:
sudo npm install
The ZenCoder's answer is spot on, but if you want to permanently fix this permissions error, you can follow the tutorial at: https://docs.npmjs.com/getting-started/fixing-npm-permissions
Since you're on a Mac, you could actually avoid npm permissions errors altogether by just installing node instead via homebrew:
brew install node (this will install npm too)
Homebrew installs programs to a directory that doesn't require sudo for write, so you can npm install -g <whatever> freely without it.