Reputation: 416
I want to deploy my code as a pipeline, once my testing job is done. How to make the login into another instance from jenkins pipeline.
First I have saved my credentials in Jenkins -
Also You can check the connection -
Jenkins SSH Connection Success
In pipeline script I am passing -
pipeline { agent any
stages {
stage('Build') {
steps {
echo 'Building..'
}
}
stage('Test') {
steps {
echo 'Testing..'
}
}
stage('Deploy') {
steps {
echo 'Deploying....'
withCredentials([string(credentialsId: '28ebc607-22f5-4fad-91f2-97de971512d3', variable: 'NUSER'),string(credentialsId: '', variable: '')]) {
sh 'pwd'
sh 'ls -l'
}
}
}
}
}
I am getting the output -
Jenkins credentials was excepted
Error -
ERROR: Credentials '28ebc607-22f5-4fad-91f2-97de971512d3' is of type 'SSH Username with private key' where 'org.jenkinsci.plugins.plaincredentials.StringCredentials' was expected Finished: FAILURE
What I am doing wrong ? What is the best way to do it ? Any suggestions ?
Upvotes: 1
Views: 7946
Reputation: 1648
I got a similar use case and I am using the ssh-agent plugin for it. You need to create a credential of type SSH and then wrap your code with it.
sshagent(credentials: ['jenkins']) {
sh ''
}
I have created my credential as example below (using private key)
jenkins=[
username: 'test',
passphrase: '',
description : 'SSH credentials',
type: 'SSH',
privateKey: ''
]
Upvotes: 0
Reputation: 1517
You probably need to use the ssh-agent plugin and wrap your ssh line with sshagent (credentials: ['deploy-dev']) { sh 'ssh server do thing' }
Upvotes: 2