Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using SSH Agent credentials in Jenkins pipeline

Tags:

ssh

maven

jenkins

I have a script for Jenkins Pipeline plugin. I already did git clone and maven build. But I have problems with transferring *.jar file to remote server. In Jenkins settings, I already have added configuration for a remote server using ssh key. And it works fine. But I can't understand how to use these settings in the pipeline script. I googled an example:

sshagent(['8e9cc002-f19dewiydtwe765-ecec834']) {
        sh "ssh user@server \"echo ${env.BUILD_ID}\""
    } 

but I can't understand where this credentials id 8e9cc002-f19dewiydtwe765-ecec834. I can use it in other Jenkins item in section Send files or execute commands over SSH - just choose credentials from the dropdown. How to configure pipeline to use this credentials (key, passphrase, username, server address etc)?

like image 790
Oleksandr H Avatar asked Feb 27 '26 15:02

Oleksandr H


1 Answers

That credential ID is specified manually when you create a credential, or Jenkins will build a big ugly one like that for you if you don't. You can see the ID back on the credentials page.

I always manually assign an ID so I don't have to work with those ugly ones, and so that it is a little more self-documenting in a jenkinsfile.

like image 87
Rob Hales Avatar answered Mar 02 '26 13:03

Rob Hales



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!