Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins ssh-agent unable to find credentials

I am trying to use ssh-agent to push commits to a remote git repository from a scripted Jenkins pipeline.

I have installed the plugin and have added the SSH private key to the Credentials section on Jenkins. THe following is a snippet from a Groovy class instantiated and called from the Jenkinsfile:

stages.sshagent(credentials:['26954b1f-2e32-4b4b-8923-3b7a9fbac6c9']) {
    stages.sh "git push origin ${branchName}"
}

Note:stages is just a representation of the stage within the Jenkinsfile. The class compiles fine but show the following error message each time:

FATAL: [ssh-agent] Could not find specified credentials

If I use the credentials with the git client then it works fine but unfortunately this does not support git push.

like image 911
JordanMazurke Avatar asked May 09 '17 12:05

JordanMazurke


People also ask

How do I find my credential ID in Jenkins?

From the Jenkins home page (i.e. the Dashboard of the Jenkins classic UI), click Manage Jenkins > Manage Credentials. Under Stores scoped to Jenkins on the right, click on Jenkins. Under System, click the Global credentials (unrestricted) link to access this default domain. Click Add Credentials on the left.

How do I log into Jenkins SSH?

Click your username in the top-right of any page in Jenkins, click Configure in the sidebar, and there you'll find a SSH Public Key textfield to paste into.


Video Answer


1 Answers

This question has a few days(944) without answer and I think you may be already solved the problem, but just for the record. I think the problem you have/had its that you haven't indicated the credential ID in your code or the ID 26954b1f-2e32-4b4b-8923-3b7a9fbac6c9 isn't the correct one.

To add a private key to Jenkins, go to:

Jenkins > Credentials > System > Global credentials

Select SSH Username with private key then in ID field

Nota: you need to have the installed the SSH Agent Plugin

Jenkins-print-screen-ssh-agent-credential

ID:

An internal unique ID by which these credentials are identified from jobs and other configuration. Normally left blank, in which case an ID will be generated, which is fine for jobs created using visual forms. Useful to specify explicitly when using credentials from scripted configuration.

Groovy code sample

sshagent(['jenkins-ssh-qa']) {
    sh "ssh -o StrictHostKeyChecking=no [email protected] ${dockerRun}"
}
like image 58
Fulvio Avatar answered Oct 16 '22 20:10

Fulvio