Improve downloadchange method
- using sshagent step instead of bash
- providing username directly from credentials
Change-Id: I944e69e9f15d46b283fb1369ab47421e10cca1b4
Related-Prod: PRODX-3456
diff --git a/src/com/mirantis/mk/Gerrit.groovy b/src/com/mirantis/mk/Gerrit.groovy
index 07c6b5d..f15785f 100644
--- a/src/com/mirantis/mk/Gerrit.groovy
+++ b/src/com/mirantis/mk/Gerrit.groovy
@@ -477,9 +477,11 @@
* @param doGitClone boolean whether to pre clone and do some checkout
*/
def downloadChange(path, url, reference, credentialsId, type = 'cherry-pick', doGitClone = true, Map gitCheckoutParams = [:]){
+ def common = new com.mirantis.mk.Common()
def git = new com.mirantis.mk.Git()
def ssh = new com.mirantis.mk.Ssh()
def cmd
+ def credentials = common.getCredentialsById(credentialsId)
switch(type) {
case 'cherry-pick':
cmd = "git fetch ${url} ${reference} && git cherry-pick FETCH_HEAD"
@@ -500,9 +502,10 @@
def depth = gitCheckoutParams.get('depth', 0)
git.checkoutGitRepository(path, url, branch, credentialsId, poll, timeout, depth, '')
}
- ssh.prepareSshAgentKey(credentialsId)
- dir(path){
- ssh.agentSh(cmd)
+ sshagent (credentials: [credentialsId]) {
+ dir(path){
+ sh(script: "GIT_SSH_COMMAND='ssh -l ${credentials.username}' ${cmd}", returnStdout:true)
+ }
}
}