通過jenkins的以下三個方式去執行sonar-scanner,拋如下錯誤。

command [cd /home/xxx/code/CODE/xxx/xxx
sonar-scanner...
bash: sonar-scanner: command not found
SSH: EXEC: completed after 200 ms
SSH: Disconnecting configuration [zftest] ...
ERROR: Exception when publishing, exception message [Exec exit status not zero. Status [127]]
Build step 'Send files or execute commands over SSH' changed build result to UNSTABLE
Finished: UNSTABLE
原因是:jenkins編譯項目,不繼承linux環境變量 ~/.bash_profile ~/.bashrc /etc/profile,導致在執行shell腳本,提示命令找不到!
解決方法:在服務器執行ln -sv /usr/local/sonar-scanner/bin/sonar-scanner /usr/local/bin/sonar-scanner
