When I use gitlab runner to package node products, an exception occurs.
I tried to provide gitlab runner permission, but it could not solve the problem for me.
Running with gitlab-runner 15.0.0 (febb2a09)
on deepin-wx mxWVNTaN
Preparing the "shell" executor
00:00
Using Shell executor...
Preparing environment
00:00
Running on deepin-wx...
Getting source from Git repository
Fetching changes with git depth set to 50...
重新初始化已存在的 Git 仓库于 /home/gitlab-runner/builds/mxWVNTaN/0/lich/npm_project_deploy/.git/
Checking out 2530949b as master...
正删除 node_modules/
Skipping Git submodules setup
Executing "step_script" stage of the job script
00:28
$ echo $CI_JOB_STAGE
build
$ whoami
root
$ whereis node
node: /usr/bin/node /root/soft/node-v16.15.0/bin/node
$ node -v
v16.15.0
$ npm config set user 0
$ npm config set unsafe-perm true
$ npm config set sass_binary_site https://npm.taobao.org/mirrors/node-sass
$ npm install --registry=http://registry.npm.taobao.org
npm WARN deprecated source-map-url#0.4.1: See supported. Upgrade to v2.x.x.
added 1381 packages in 27s
$ chmod -R 755 ./*
$ npm run build
> npm_project_deploy#0.1.0 build
> vue-cli-service build
/usr/bin/env: “node”: 权限不够
ERROR: Job failed: exit status 1
screenshoot
screenshoot
If you’ve already tried to change the gitlab-runner users permissions - then you could try adding sudo to your npm based commands. I wouldn’t recommend this though.
I think using a shell runner is not the right way to go if you are looking to create real ci (unless you are creating a fresh host for each ci pipeline).
I would recommend looking into the gitlab runner docker executor and using a docker image that has node and the rest of the things you need in an environment set up.
Related
I am using node version 4.4.5 and npm version is 5.3.0.
jenkins version is 2.46.2.
At the time of build I am getting this exception:
/bin/sh -xe /tmp/hudson7756731843340614304.sh
+ PATH=/sbin:/usr/sbin:/usr/bin:/usr/local/bin
+ npm install
/tmp/hudson7756731843340614304.sh: 6: /tmp/hudson7756731843340614304.sh: npm: not found
Build step 'Execute shell' marked build as failure
The execute shell consist of:
#echo "PATH is :$PATH"
#echo "node version is :'node -v' "
#echo "npm version is:'npm -v' "
PATH=/sbin:/usr/sbin:/usr/bin:/usr/local/bin
npm install
npm run coverage
zip -r EngagementSystemNodeApi.zip .
What need to be done plz suggest.
Don't run npm from the commandline. Install and use Jenkins NodeJS plugin. It allows you to configure multiple versions of node and it puts them on the PATH
have you set the enviroment variable in the jenkins machine?
I'm running a nodejs application's build on jenkins. I run node as shell script step, because I have some limitations in terms of the plugins I can install in this jenkins instance.
This is what the npm install step looks like:
#!/bin/bash +x
source ~/.bashrc
cd $WORKSPACE/ && \
nvm use 7.8.0 && node --version && npm install
The problem I have is, when npm install finishes, it doesn't install everything. If I ssh into the box where jenkins is installed and run npm install inside that project's workspace, with the same user jenkins uses, it works ok. Any ideas?
EDIT
I just realized the dependencies that it's not installing are devDependencies
The problem was I had the node env set to production, and of course, it wouldn't get the devDependencies...
As part of the setup for building my environment for a job in Jenkins, I have checked the
Provide Node & npm bin/ folder to PATH
At the moment it defaults to Installation NodeJS
When running a job it gets to this point
$ /Users/jenkins/.jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS/bin/npm install -g grunt-cli
but returns
env: node: No such file or directory
When manually going to the npm folder I cannot cd into it but a ls -la outputs
npm -> ../lib/node_modules/npm/bin/npm-cli.js
What is happening here, and why am I getting the error?
Problem
I created a project where configure a server in DigitalOcean with Apache and Git.
For init project on server, I run the following command:
cd /var/repo
mkdir project-example.git && cd project-example.git
git init --bare
I set up file post-receive with this code:
#!/bin/bash
git --work-tree=/var/temp/project-example --git-dir=/var/repo/project-example.git checkout -f
cd /var/temp/project-example
npm install
npm run build
rm -rf /var/www/project-example/*
mv -f /var/temp/project-example/build/* /var/www/project-example/
When I make a push to server remote via git on machine local, occurs followings errors:
remote: hooks/post-receive: line 4: npm: command not found
remote: hooks/post-receive: line 5: npm: command not found
However, accessing server via SSH and execute command:
# it works standard
cd /var/repo/project-example.git
source hooks/post-receive
Comments
System Server: Ubuntu 14.04
I installed node via nvm.
When a git hook runs, it does not necessarily have the same PATH variable set as when you log in via SSH. Try putting the full path to npm in your script when you call it; that should fix things.
UPDATE (June 7 2019):
A couple of commenters had issues with node not being found when using the above solution, which made me realize it is not very robust. Rather than put the path in the call to npm itself, you'd be better off adding the necessary path to the script's environment, e.g. if npm (and node) happen to be in /usr/bin/, add the following to your script before calling npm:
export PATH=$PATH:/usr/bin
In fact, a more robust way to make sure the hook works the same as it does when you are logged in via SSH is to find out what the path is when you are logged in (i.e. the output of echo $PATH) and set the path in your hook script accordingly (of course you may need to omit some user-specific paths, etc.)
The application I want to implement continuous deployment on Bamboo has node modules and bower component dependencies. On the bamboo server nodejs, npm have been installed.
There are only three tasks on default job:
Source Code Checkout
Build dependencies:
npm install
bower install
Deploy to the staging server
The problem is on the second task, bamboo fails with the message "No failed tests found, a possible compilation error occurred." I don't even run any tests.
The log file is not explanatory at all:
Starting task 'Build dependencies' of type 'com.atlassian.bamboo.plugins.scripttask:task.builder.script'
Failing task since return code of [/bin/sh /home/ubuntu/bamboo-installation/temp/WEB-WEB-JOB1-8-ScriptBuildTask-4430338079602360707.sh] was 1 while expected 0
Ok, I solved the problem. The issue was the wrong node (which obviously messed things up) was installed on the bamboo server. Uninstalled the wrong one and everything worked as expected.
Good to see you solved it.
There is a setup I use and which could prevent further problems with CI:
export npm_config_prefix=.npm/
export PATH=.npm/bin:$PATH
export CI=true
npm install -g bower
bower install
npm install
This installs bower (and others like grunt-cli if you want) in your project folder so you can e.g. have a specific version, sets CI=true as advised in bower docs, and then installs all dependencies.
Bamboo AMI originally have npm version 1.4.28 installed and you are probably using a more recent version on you development environment. I had the same issue and resolved it by creating a script task to update npm version on the very beginning of my build process. Here is the script:
# update npm
curl -O -L https://npmjs.org/install.sh
chmod +x install.sh
sudo PATH=$PATH:/opt/node-0.10/bin ./install.sh