+/usr/local/node/bin/npm -v
/usr/bin/env: node: 没有那个文件或目录
切换Jenkins用户,把PATH环境变量的置设置到Jenkins全局配置中:
su - jenkins
echo $PATH
+/usr/local/node/bin/npm run build
npm ERR! missing script: build
npm ERR! A complete log of this run can be found in:
查看当前项目中的package.jsonwen文件,如果script中写法是"build:stage",那么执行npm run build:prod
+cp -a dist /usr/local/nginx/
cp: 无法创建目录"/usr/local/nginx/dist": 权限不够
由于安装nginx用的是root用户安装的,所属组和主也是root,把nginx路径修改为jenkin或者把jenkins用户添加到root组中,然后看一下目录权限。
chown root.jenkins -R nginx | usermod -a -G jenkins root
chmod 660 -R html
[warn] 23691#23691: the “user” directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:5
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
2021/12/30 06:00:08 [emerg] 23691#23691: open() “/run/nginx.pid” failed (13: Permission denied)
为构建命令添加sudo,同时在root下,编辑/etc/suduers文件,为jenkins添加相关命令的权限
[root@xxx] # visudo
Build step ‘Execute shell’ marked build as failure
在构建第一行添加#!/bin/bash
java.io.IOException: Cannot run program “java” (in directory “/var/lib/jenkins/workspace/xxxx”): error=2, 没有那个文件或目录
使用Send files or execute commands over SSH时报错,说不能运行java,但是JAVA_HOME也设置好了,估计是jenkins只从/usr/bin/java找,添加一个软连接就好了:
ln -s $JAVA_HOME/bin/java /usr/bin/java