如何在詹金斯(Jenkins)的URL中传递credentialID [英] How to pass credentialID in the url in Jenkins

查看:121
本文介绍了如何在詹金斯(Jenkins)的URL中传递credentialID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下命令:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆