本机shell命令可以正确执行,但Jenkins任务中无法执行,提示“未找到命令”,比如未找到ant或者mvn:
Started by user admin
Running as SYSTEM
Building remotely on 172.20.1.156-dms in workspace /home/smart/jenkins/workspace/Dms-Web-Jars
[Dms-Web-Jars] $ /bin/bash /tmp/jenkins7910466140349651313.sh
Current location /root/JavaWorkspace/dms-projects
**************开始编译Dms******************
step1. go into Dms
step2. svn update /root/JavaWorkspace/dms-projects/Dms
正在升级 '.':
U src/com/sf/web/dms/msgconsumers/control/SubMessageControl.java
更新到版本 17081。
step3. clean classes
step4. ant build /root/JavaWorkspace/dms-projects/Dms/build.xml
./build.sh:行26: ant: 未找到命令
原因是Jenkins没有加载/etc/profile导致,Jenkins默认情况下执行shell脚本是使用非登录方式,然而非登录方式不会加载 /etc/profile 文件,因此在Jenkins任务的Execute shell 中 添加如 #!/bin/sh -l 命令修改为登录方式即可解决问题