I use Jenkins for CICD. After cloning the repository, I want to copy some file from cloned repository to a remote server using sshpass (scp).
sh """sshpass -p '$KEY'-o StrictHostKeyChecking=no scp *.json $UNAME@$PROD_IP:/home/test"""
But I get error in output:
sshpass: Failed to run command: No such file or directory
What's wrong I'm doing ?
After a long search I found the answer. So, you need to switch to the jenkins user and create a pair of keys on his behalf and add to the remote server to which you need to access. Then add the private key into Jenkins credential and use.