'Jenkins : Permission denied (publickey,password)

I'm trying to copy files using scp command from jenkins (ci/cd). But i got permission denied error. If i'm trying manually from diffrent servers, its all done, at the same time i tried the same command in jenkins exes command, then i got error.

Configure > Build > execute shell

and the console output is like below,

[nginx_server] $ /bin/sh -xe /tmp/jenkins7685256768444698.sh

  • scp 111 [email protected]:/home/ubuntu Permission denied, please try again. Permission denied, please try again. [email protected]: Permission denied (publickey,password). lost connection Build step 'Execute shell' marked build as failure Finished: FAILURE

if anyone know the solution, please answer...



Solution 1:[1]

Add your ssh key as a secret to Jenkins.

In your pipeline use sshagent:

pipeline {
    stages {
        stage('Stage_name') {
            steps {
                script {
                    sshagent (credentials: ['secret_name']) {
                        sh "scp ... "
                    }
                }
            }
        }
    }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 cheburek