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)
hakamairi
  • 4,464
  • 4
  • 30
  • 53
CEamonn
  • 853
  • 14
  • 37

1 Answers1

0

The way to do this is to call the variable without quotes or $, as below

def remote = [:]
remote.name = 'EU Server 1'
remote.host = 'server1@server.com'
remote.user = username
remote.password = password
remote.allowAnyHosts = true
CEamonn
  • 853
  • 14
  • 37
  • https://stackoverflow.com/questions/6761498/whats-the-difference-of-strings-within-single-or-double-quotes-in-groovy – hakamairi Jan 14 '19 at 12:06