node.jsgitlabgitlab-cigitlab-runner

/usr/bin/env: “node”: Permission denied


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


Solution

  • 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.