I have some Jenkins jobs defined using a Jenkins Pipeline Model Definition, which builds NPM projects. I use Docker containers to build these projects (using a common image
I had a similar issue. I did not use label 'master', and I identified that the file transfer works across slaves, when I do it like this:
Step 1 - create SSH keys in remote host server, include the key to authorized_keys
Step 2 - Create credential using SSH keys in Jenkins, use the private key from the remote host
The below step is added to the pipeline:
stage ('Deploy') {
steps{
sshagent(credentials : ['use-the-id-from-credential-generated-by-jenkins']) {
sh 'ssh -o StrictHostKeyChecking=no user@hostname.com uptime'
sh 'ssh -v user@hostname.com'
sh 'scp ./source/filename user@hostname.com:/remotehost/target'
}
}
}