想问下为什么会
$ echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/home/gitlab-runner/.local/bin:/home/gitlab-runner/bin $ npm install --no-optional --registry=https://registry.npm.taobao.org bash: line 85: npm: command not found ERROR: Job failed: exit status 1
npm 找不到是为什么
default: image: node:latest stages: - lint cache: paths: - node_modules/ test: stage: lint before_script: - echo $PATH script: - npm install --no-optional --registry=https://registry.npm.taobao.org - npm run lint only: - master - dev
1 br_wang 2021-02-20 15:20:34 +08:00 你再 node -v 一下,看看是不是 node 也没有。 感觉是镜像那里,为啥要 default 阿?不是直接 image 就可以? |
2 xiaohantx OP @br_wang 是可以,我原来写的就是直接 ``` image: node:latest stages: - lint cache: paths: - node_modules/ test: stage: lint before_script: - echo $PATH script: - npm install --no-optional --registry=https://registry.npm.taobao.org - npm run lint only: - master - dev ``` 但是也不行所以就试试- -忘记删了。。docker 镜像里应该有环境的呀。。 |
3 chenluo0429 2021-02-20 15:23:42 +08:00 执行指令的用户是 gitlab-runner,盲猜你的 npm 是在当前用户 home 目录下,比如我用的 nvm 管理 node 就在 /home/dev/.nvm 下面。可以用 whereis npm 看看 npm 究竟在什么目录下。 或者也可能是没有访问权限。 |
5 xiaohantx OP @chenluo0429 是要联系管理员在当前用户配置环境嘛,我以为会自动拉 docker 镜像然后里面有 node...和 npm |
7 xiaohantx OP @br_wang 现在写的是 ``` image: node:latest stages: - lint cache: paths: - node_modules/ test: stage: lint before_script: - node -v script: - npm run lint only: - master - dev ``` |
![]() | 8 wxsm 2021-02-20 15:35:57 +08:00 你可以在执行 npm 之前打印一下 whoami,肯定不对 |
![]() | 10 wxsm 2021-02-20 15:48:01 +08:00 via iPhone @xiaohantx 你这个 runner 确定是以 docker 模式运行的吗,确定不是配了 shell 模式吗 |
![]() | 11 AngryPanda 2021-02-20 15:51:19 +08:00 via iPhone npm 在 path 下面吗?或者直接写绝对路径 |
12 xiaohantx OP @AngryPanda 用 which 找,找不到 |
13 xiaohantx OP @wxsm 这两个是有区别的嘛....我不确定因为我看大部分文档没有提到有 docker 和 shell 两种模式都是直接的 docker |
14 xiaohantx OP @AngryPanda node 都没有目前来看 |
15 xiaohantx OP @wxsm 看后端的打包命令有这个 ``` docker-build: stage: package dependencies: - maven-build script: - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY - docker build -t $CI_REGISTRY_IMAGE:latest . - docker push $CI_REGISTRY_IMAGE:latest only: - develop ``` |
![]() | 16 wxsm 2021-02-20 16:09:17 +08:00 @xiaohantx 你可以看一下 CI 的执行日志,开头几行会有类似 `Using Shell executor` 的输出,如果是 Shell 说明配错了,你在 yarml 里面指定了 image 没有用,它会直接在宿主机上执行。如果是 Using Docker executor,那才是对的。 |
![]() | 17 mitsuizzz 2021-02-20 16:10:10 +08:00 把 images 移动到 test 里试试 test: stage: lint image: node:12-alpine before_script: - echo $PATH script: - npm install --no-optional --registry=https://registry.npm.taobao.org - npm run lint only: - master - dev |
![]() | 20 wxsm 2021-02-20 16:13:03 +08:00 @xiaohantx Shell 模式写 image 没有用,会被忽略。这个需要重新配置一下 runner,或者放弃使用 docker,在 runner 宿主机上安装 nodejs,两种方式都行。 |
23 nano91 2021-02-20 16:21:48 +08:00 whereis 看看 |
![]() | 24 wxsm 2021-02-20 16:27:08 +08:00 @xiaohantx 你贴的 docker-build 也是个 CI 任务,估计是你们后端用来打包上传镜像用于部署的,跟 runner 没有关系 |