如何在詹金斯(Jenkins)的URL中传递credentialID [英] How to pass credentialID in the url in Jenkins
问题描述
我正在使用以下命令:
sh 'git push https://${userid}:${passwd}@innersource.com/scm/raghu/demo.git'
但是我想使用-凭据ID:'f0079d43-9522-4133-9601-89c81f8ce7c9',而不是ID和密码,我想在URL中传递凭据ID(
But I want to use - credentialsId: 'f0079d43-9522-4133-9601-89c81f8ce7c9', instead of id and password and I want to pass credentialsId in the URL (https://innersource.com/scm/raghu/demo.git)
我该怎么做?
推荐答案
您可以在管道阶段将凭据绑定插件与usernameColonPassword
属性一起使用.这还将在控制台日志中将凭据屏蔽为****
.
You can use the Credentials Binding Plugin with usernameColonPassword
property in your pipeline stage. This will also mask the credentials in console log as ****
.
stage(git-push) {
withCredentials([usernameColonPassword(credentialsId: 'f0079d43-9522-4133-9601-89c81f8ce7c9', variable: 'USERPASS')]) {
sh 'git push https://${USERPASS}@innersource.com/scm/raghu/demo.git'
}
}
从文档:
usernameColonPassword
将变量设置为凭据中给定的用户名和密码,并用冒号(:)分隔.
usernameColonPassword
Sets a variable to the username and password given in the credentials, separated by a colon (:).
这篇关于如何在詹金斯(Jenkins)的URL中传递credentialID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!