### Use withCredentials for SSH Key Binding Source: https://plugins.jenkins.io/ssh-agent Utilize the generic `withCredentials` step to bind an SSH private key to a temporary file. This is useful for passing the key to commands like `ssh` or `scp` using the `-i` option. ```groovy withCredentials([sshUserPrivateKey(credentialsId: 'github', keyFileVariable: 'PK')]) { sh 'git -c core.sshCommand="ssh -i $PK" submodule update --init' } ``` -------------------------------- ### Manual ssh-agent with sshUserPrivateKey Source: https://plugins.jenkins.io/ssh-agent Manually manage `ssh-agent` within a build using `withCredentials` to add an SSH private key. This approach is useful for customizing `ssh-agent` options. ```groovy withCredentials([sshUserPrivateKey(credentialsId: 'github', keyFileVariable: 'PK')]) { sh ''' eval `ssh-agent -s` trap "ssh-agent -k" EXIT ssh-add "$PK" # rest of script… ''' } ``` -------------------------------- ### Use sshagent Step in Pipeline Source: https://plugins.jenkins.io/ssh-agent Use the `sshagent` step within a Pipeline job to provide SSH credentials. Ensure the credentials ID is correctly specified. ```groovy steps { sshagent(credentials: ['ssh-credentials-id']) { sh ''' [ -d ~/.ssh ] || mkdir ~/.ssh && chmod 0700 ~/.ssh ssh-keyscan -t rsa,dsa example.com >> ~/.ssh/known_hosts ssh user@example.com ... ''' } } ``` -------------------------------- ### Declare SSH Agent Plugin Dependency in Maven POM Source: https://plugins.jenkins.io/ssh-agent/dependencies Add this dependency to your plugin's POM to use the SSH Agent plugin. It is recommended to use the Jenkins plugin BOM to avoid version conflicts. ```xml org.jenkins-ci.plugins ssh-agent ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.