Passing the PASSWORD credentials variable from Jenkins to sshpass in a script

Multi tool use
Multi tool use


Passing the PASSWORD credentials variable from Jenkins to sshpass in a script



I've setup some global credentials in jenkins, username password type.



I've now got to scp a file over to a target server inside my pipeline.



For arguments sake, lets say my password variable is secretpassword.



Does anyone know how to get the password to work properly with sshpass?



Here's the gist of what I'm trying to do


sh '''
sshpass -p'${PASSWORD}' scp ${WORKSPACE}/target/citest-1.0-SNAPSHOT.jar root@target_service:/
'''



Whatever I try I can't seem to get the syntax right for passing the password to sshpass



If I do the following, it works fine


sh '''
sshpass -p 'secretpassword' scp ${WORKSPACE}/target/citest-1.0-SNAPSHOT.jar root@target_service:/
'''



So I'm obviously just messing up how to get the PASSWORD env variable to spit out properly into the single quotes.



I seem to have tried a few thousand options so far, does anyone have any bright ideas?



Thanks in advance




2 Answers
2



Try without single quotes.



sshpass -p ${PASSWORD} scp ${WORKSPACE}/target/citest-1.0-SNAPSHOT.jar root@target_service:/


sshpass -p ${PASSWORD} scp ${WORKSPACE}/target/citest-1.0-SNAPSHOT.jar root@target_service:/



Is there any specific reason to keep it in single Quotes? because single quote will not interpolate variable.



Use ''' only if you have multiple sh commands to run, if it just a single command then do it like so and it should work fine


'''


sh "sshpass -p ${PASSWORD} scp ${WORKSPACE}/target/citest-1.0-SNAPSHOT.jar root@target_service:/ "



if you need to use '''


'''



then use it without the single quotes


sh '''
sshpass -p ${PASSWORD} scp ${WORKSPACE}/target/citest-1.0-SNAPSHOT.jar root@target_service:/
'''






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Vo4cnVzPqSUECG CubLIIld7cY,SDZo,GQerrow,KV5JxBe9TTO0j5,W5 lYNWveG 3Hjv1Ii8AZTyJ 3aol,hTt0K
9BrJuK,rNKn253C r0FU5CnXcBR5DdfT

Popular posts from this blog

Rothschild family

Cinema of Italy