Rinshad
Rinshad

Reputation: 13

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...

Upvotes: 0

Views: 891

Answers (1)

dyvopes
dyvopes

Reputation: 141

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 ... "
                    }
                }
            }
        }
    }
}

Upvotes: 0

Related Questions