简体   繁体   English

在脚本中将PASSWORD凭据变量从Jenkins传递到sshpass

[英]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. 现在,我必须将文件scp传输到管道中的目标服务器。

For arguments sake, lets say my password variable is secretpassword. 出于参数考虑,可以说我的密码变量是secretpassword。

Does anyone know how to get the password to work properly with sshpass? 有谁知道如何获取密码才能与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 无论我如何尝试,我似乎都无法正确理解将密码传递给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. 因此,我显然只是在弄乱如何获取PASSWORD env变量以将其正确吐出到单引号中。

I seem to have tried a few thousand options so far, does anyone have any bright ideas? 到目前为止,我似乎已经尝试了数千种选择,有人有什么好主意吗?

Thanks in advance 提前致谢

Try without single quotes. 尝试不使用单引号。

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命令要运行时才使用''' ,如果只是一个命令,则应这样做,它应该可以正常工作

 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:/
'''

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM