如何在詹金斯(Jenkins)的网址中传递credentialID

时间:2019-10-28 20:11:34

标签: git jenkins

我正在使用以下命令:

sh 'git push https://${userid}:${passwd}@innersource.com/scm/raghu/demo.git'

但是我想使用-凭据ID:'f0079d43-9522-4133-9601-89c81f8ce7c9',而不是ID和密码,我想在URL(https://innersource.com/scm/raghu/demo.git)中传递凭据ID

我该怎么做?

2 个答案:

答案 0 :(得分:0)

environment {
    NEXUS_REPO = credentials('nexus-repo-credentials')
    GITHUB_AUTH_TOKEN = credentials('jx-release-version-github-token')
    GITHUB_REPO = 'demo'
}

可以逐步使用

sh "git remote set-url origin git@github.com:innersource.com/scm/raghu/${GITHUB_REPO}.git"

答案 1 :(得分:0)

您可以在管道阶段将凭据绑定插件usernameColonPassword属性一起使用。这还将在控制台日志中将凭据屏蔽为****

stage(git-push) {
  withCredentials([usernameColonPassword(credentialsId: 'f0079d43-9522-4133-9601-89c81f8ce7c9', variable: 'USERPASS')]) {
    sh 'git push https://${USERPASS}@innersource.com/scm/raghu/demo.git'
  }
}

来自documentation

  

usernameColonPassword   将凭据中指定的用户名和密码设置为变量,并用冒号(:)分隔。