0

I have a basic Pipeline that copies a directory to a remote directory. If i have the username and password in plain text it works fine, but when I try to use withCredentials I get authentication errors. Is there a certain syntax to reference this? Pipeline is as below

node {
    withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'creds-id', usernameVariable: 'username', passwordVariable: 'password']]){

    def remote = [:]
    remote.name = 'EU Server 1'
    remote.host = 'server1@server.com'
    remote.user = '$username'
    remote.password = '$password'
    remote.allowAnyHosts = true

    stage('Copy dir to server'){
        sshPut remote: remote, from: '/data/workspace', into: '/home/server1/workspace1'
    }
}

I'm getting the error below

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)
CEamonn
  • 101
  • 2

2 Answers2

0

Use double quotes instead of single quotes. Single quotes prevents string interpolation:

remote.user = "$username"
remote.password = "$password"
jayhendren
  • 917
  • 4
  • 11
0

Answer to this was no quotes/var characters

remote.user = username
remote.password = password
CEamonn
  • 101
  • 2