Use ssh credentials in jenkins pipeline with ssh, scp or sftp

Solution:

    withCredentials([sshUserPrivateKey(credentialsId: "yourkeyid", keyFileVariable: 'keyfile')]) {
       stage('scp-f/b') {
        sh "scp -i ${keyfile} do sth here"
       }
   }

Maybe this is what you want. Install Credentials Plugin and
Credentials Binding Plugin. Add some credentials and then you will get "yourkeyid", bind this credentials to keyFileVariable, passwordVariable etc.

More details and documentation can be found on the Github site of the Jenkins Credentials Binding Plugin, Credentials Plugin, SSH Pipeline Steps plugin


If you install the SSH Agent plugin you can use the ssh-agent pipeline step to run a shell script with an ssh-agent active. The ssh-agent takes a Jenkins credentials ID (a passworded ssh cert, like the one you have for git).