Create Multiple SSH Connection in jenkins

My requirement is like this: The jenkins is installed in one server(say server A). I have 3 script in this server for deployment of war into different server say B and C.

There is a main script say JenkinsMainScript.sh . Inside this script I have copied the deployment script(say serverB.sh/serverC.sh) from server A to the Corresponding server serverB or serverC based on parameter passed when execute the shell like :

/root/Pictures/JenkinsTesting/JenkinsBuildMain.sh B

in the jenkins’s “Execute shell” under “Build” section of jenkins of a job where B is the server Name to deploy. i.e if I again pass C as parameter in the above statement then the main script will copy serverC.sh from server A to server C and deploy the war into that server Note:-All the deployment steps are written inside serverC.sh for server C and serverB.sh for Server B.

Again My deployment is of two steps in jenkins, Job1 and Job2.

1.Create war file by taking source as git repository which is access using SSH(say server D) 2.After Successful execution of Job1 it will trigger Job2.

Inside Job2 I am executing the JenkinsBuildMain.sh file under Build section.

The Problem is If I add id_rsa and id_rsa.pub file inside .ssh directory of jenkins to access git server(server D) at the same time I can’t access other server like server B for deployment via SSH connection. Again if I add id_rsa and id_rsa.pub file inside .ssh for deployment server(server B) then Git server is unable to access at the same time. That means only one server is accessible using SSH connection at a time.

Is there any way to access both server using same key or different key?

Or can we add multiple key for ssh connection so that it can access to both server, server D for git clone and server B for copying the script file from jenkins server to server B.

When I do this I got Bellow Message: “Host key verification failed. lost connection”

Current I am able connect one server at a time. If It connect to Git server the shell script file is not able to copy ,saying above error, and if I able set up for copying the file the git Server is unable to access saying

Return status code 128. Permission denied (PublicKey,gssapi-keyex,gssapi-mic,password)…

Is There any way to add multiple keys for ssh connection for different server using Jenkins?

Bellow is my script Code to copy the deploy script to remote server.

JenkinsMainScript.sh:

if [ $serverId = ‘B’ ]
then
scp $scriptSourcePath/serverB.sh $serverBPathToCopyTheFile/
ssh -l $serverBUserName $IpAddr $serverBPathToExecuteTheFile/serverB.sh

else
echo " No Matching condition found…"
fi

Here is the screen shot of Configuration in the Jenkins for job2:

Jenkins Config for job2

Can anyone help me on this. Thanks in advance