Not sure if this will format correctly, but hopefully gives you enough of an idea: import java.text.SimpleDateFormat node { def dateFormat = new SimpleDateFormat("yyyyMMddHHmm") sourcefile="server.log" String partialFileName = " " + sourcefile + "${MAL}" + dateFormat.format(new Date()) + "soc" servers = ['10.xxx.xxx.xxx',] def soc_remote = [:] soc_remote.name = "${MAL} SOC" soc_remote.allowAnyHosts = true soc_remote.fileTransfer = 'scp' withCredentials([usernamePassword(credentialsId: 'Credentials', usernameVariable: 'USER_ID', passwordVariable: 'USER_PASSWORD')]) { soc_remote.user = USER_ID soc_remote.password = USER_PASSWORD servers.each { server -> String FileName = partialFileName + server + ".txt" echo "${FileName}" soc_remote.host = server stage("Run log gather script on ${server}") { sshCommand remote: soc_remote, command: "ls -ltr /srv/jboss/server/${MAL}/log/${sourcefile}" } stage("Download ${MAL} logs from ${server}") { dir("D:\\Logs\\${MAL}\\logs ${server}") { try { def commandResult = sshGet remote: soc_remote, from: "/srv/jboss/server/${MAL}/log/${sourcefile}", into: FileName, override: true } catch (err) { echo "something failed" echo "${err}" } } } } } } |