我有一个基本的管道,用于将目录复制到远程目录。如果我有纯文本的用户名和密码,它可以正常工作,但当我尝试使用 withCredentials 时,我收到身份验证错误。是否有特定的语法可以引用此语法?管道如下
node {
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'creds-id', usernameVariable: 'username', passwordVariable: 'password']]){
def remote = [:]
remote.name = 'EU Server 1'
remote.host = '[email protected]'
remote.user = '$username'
remote.password = '$password'
remote.allowAnyHosts = true
stage('Copy dir to server'){
sshPut remote: remote, from: '/data/workspace', into: '/home/server1/workspace1'
}
}
我收到以下错误
com.jcraft.jsch.JSchException: Auth fail
at com.jcraft.jsch.Session.connect(Session.java:519)
at com.jcraft.jsch.Session.connect(Session.java:183)
at com.jcraft.jsch.Session$connect$6.call(Unknown Source)
答案1
使用双引号代替单引号。单引号可防止字符串插值:
remote.user = "$username"
remote.password = "$password"
答案2
答案是没有引号/var 字符
remote.user = username
remote.password = password