Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass password through jenkins build step

I'm trying to add a build step in jenkins to copy files from my build server to my web application server. I've got the following command working in the command prompt

sudo scp -r /var/lib/jenkins/workspace/demoproj/publish [email protected]:/usr/temp

but when I run this command, it prompts me for a password every time. I found out about sshpass, but when I run this command...

sudo sshpass -p "passwordhere" scp -r /var/lib/jenkins/workspace/demoproj/pub [email protected]:/usr/temp

the terminal gets stuck. And never makes it through.

My main problem is if I add the first command to a build step in jenkins, it won't be able to pass the password over. How can I either supply the password in jenkins, or modify the command to pass over my credentials?

Helpful information: I'm using Putty on Windows 10 to connect to my Ubuntu 16.04.3 LTS x64 servers from another Ubuntu 16.04.3 server.

like image 600
ddeamaral Avatar asked Oct 27 '25 01:10

ddeamaral


1 Answers

First, sshpass needs to be installed on both the systems that is, the one running your jenkins instance as well as the one you are trying to access that is: [email protected]. You can verify it by doing 'which sshpass' or 'whereis sshpass'. If its not installed even in one of them then you need to install it first.

Also, Have you ever tried doing a ssh to the said machine: [email protected] from the system where you have your jenkins instance? If not then there might not be an entry in the 'known-hosts' of either system. for that you can do ssh with '-o StrictHostKeyChecking=no' option to make an automatic entry in known-hosts.

Alternatively, if you dont want to enter password again and again you should work with 'keys'. Generate a unique key for both the systems and do an scp or ssh with -i option.

You should use jenkins credentials instead of using sensitive passwords directly into the scripts. Put the whole scp or ssh part inside a block which looks like: withCredentials(){}.

like image 98
Arun.D Avatar answered Oct 28 '25 15:10

Arun.D



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!