Issue
im using jenkins on MAC to make CI environment and encounter this issue. log on jenkins console output:
sh: sshpass: command not found
my jenkins shell
python $path_python_script"/copy.py"
copy.py
import os
import ssh
import paramiko
import shutil
import sys
cmmd = "sshpass -p *** scp -r /srcpath [email protected].***.***:/destpath"
os.system(cmmd)
however when i execute the python file on terminal, it definitely works.
appreciate any help.
Solution
When an application can be executed in the terminal but can’t be found when invoked via a script on the same machine, most of the times the issue is the PATH
environment variable, which is where applications are searched.
The problem can be solved either
- by adjusting the
PATH
environment variable in the calling script, or - by specifying the full path when invoking the binary.
Either way, you will need to figure out where the application is located, by executing (in the terminal)
which sshpass
The result is the full path to the sshpass
exucutable. You can now use that inside your cmmd
variable in the script, or you can leave cmmd
as-is, and adjust PATH
before invoking it:
os.environ["PATH"] += os.pathsep + path_to_sshpass
Make sure to use the directory name, not the full path. That is, if the full path is /usr/local/bin/sshpass
, then path_to_sshpass
should be '/usr/local/bin'
.
Answered By - Konrad Rudolph
Answer Checked By - Marie Seifert (JavaFixing Admin)