解决Jenkins 运行shell脚本是报错,/bin/sh: line 1: allure: command not found

解决Jenkins 运行shell脚本是报错,/bin/sh: line 1: allure: command not found

本地执行shell命令成功,Jenkins 远程执行 shell命令有时 提示命令找不到,或者make的时候报错。

因为Jenkins执行shell时无法获取环境变量的原因导致

解决办法在shell脚本上加上环境变量如:

复制代码
#!/bin/bash
source ~/.bash_profile
source /etc/profile

在shell脚本里面添加了后,Jenkins就能正常的运行shell脚本;

第二种解决办法:

本机shell命令可以执行,jenkins任务中无法执行,则是jenkins没有加载/etc/profile导致,需要在jenkins调用shell脚本的最前面加一行脚本,#!/bin/bash -ilex,可以通过-i参数和-l参数让bash为login shell and interactive shell,就可以读取/etc/profile和~/.bash_profile等文件

shell脚本:

#!/bin/bash -ilex

相关推荐
C+++Python24 分钟前
Linux/C++多进程
linux·运维·c++
最贪吃的虎25 分钟前
GitHub推送又超时了?试试SSH
运维·ssh·github
XZY02834 分钟前
如何使用grpc
运维·服务器
rleS IONS37 分钟前
SQL2000在win10上安装的方法
运维·服务器
zly35001 小时前
centos7 sshd无法启动
linux·运维·服务器
编程大师哥2 小时前
Linux 命名管道(FIFO)通信 超清晰讲解
linux·运维·服务器
Smile_2542204182 小时前
linux服务器清理磁盘
linux·运维·服务器
KivenMitnick2 小时前
Claude Code--Ubuntu Linux超详细配置教程(附每步的可能报错及解决方法)
linux·运维·ubuntu
JoyCong19983 小时前
OpenClaw实践玩法,简单三步搭建自动化工作流(附真香平替方案)
运维·人工智能·自动化