Jenkins withCredentials是否支持用户域凭据?报错咨询
问题
在Jenkins个人配置页面(路径:Dashboard > USERID > Credentials > User > Global credentials (unrestricted))中定义了用户名/密码类型的用户凭据,运行以下Pipeline代码时出现报错,但使用系统域凭据则可正常执行。
Pipeline代码
withCredentials([usernamePassword(credentialsId: 'CRED_ID', usernameVariable: 'aUser', passwordVariable: 'aPassword')]) { some code }
报错信息
WARNING: Unknown parameter(s) found for class type 'org.jenkinsci.plugins.credentialsbinding.impl.StringBinding': passwordVariable,usernameVariable
ERROR: Could not find credentials entry with ID 'CRED_ID'
咨询:withCredentials 是否支持用户域凭据?
相关版本:Jenkins 2.414.1、Credentials Binding Plugin 642.v737、Credentials Plugin 1319.v7
回答
withCredentials完全支持用户域凭据,报错核心原因是Pipeline无法定位到个人用户域下创建的凭据,参数不匹配警告属于定位失败引发的连锁提示。- 解决步骤:
- 指定凭据完整域路径:个人用户域的凭据ID需要带上域标识,格式为
user:你的用户名:CRED_ID。修改后的Pipeline代码如下:withCredentials([usernamePassword(credentialsId: 'user:你的用户名:CRED_ID', usernameVariable: 'aUser', passwordVariable: 'aPassword')]) { some code } - 验证凭据权限:确保运行Pipeline的Jenkins用户(或任务执行代理用户)拥有该个人域凭据的「读取」权限,可在凭据配置页的权限选项中添加对应权限。
- 确认凭据类型匹配:确保创建的凭据为「用户名和密码」类型,而非字符串等其他类型,避免参数不匹配警告。
- 指定凭据完整域路径:个人用户域的凭据ID需要带上域标识,格式为
内容的提问来源于stack exchange,提问作者freeAR
相关产品推荐
相关产品推荐

