Jenkins流水线脚本中‘Secret Text’对应的credentialType值是什么?
Jenkins流水线参数化任务:Secret Text凭据类型配置问题
你尝试为参数化任务创建流水线脚本,指定Secret Text类型的凭据作为输入,使用代码:
credentials(name: 'API_TOKEN', description: 'API Access Token', defaultValue: '', credentialType: "Secret Text", required: true )
但生成的任务输入配置中,凭据类型过滤器被设为“Any”,手动修改为“Secret text”后过滤正常,却无法通过脚本初始设置正确值。
解决方案
正确的credentialType值需要填写Secret Text凭据对应的实现类完整路径,有两种有效写法:
- 直接引用类对象:
credentials(name: 'API_TOKEN', description: 'API Access Token', defaultValue: '', credentialType: org.jenkinsci.plugins.plaincredentials.StringCredentials, required: true )
- 使用完整类名字符串:
credentials(name: 'API_TOKEN', description: 'API Access Token', defaultValue: '', credentialType: "org.jenkinsci.plugins.plaincredentials.StringCredentials", required: true )
说明
流水线脚本的credentialType参数不接受GUI显示的友好名称(比如"Secret Text"),而是需要对应凭据类型的实现类对象或完整类名字符串。不同凭据类型对应不同的实现类,例如:
- Username with password 对应
com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl - Secret Text 对应
org.jenkinsci.plugins.plaincredentials.StringCredentials
内容的提问来源于stack exchange,提问作者aerion
相关产品推荐
相关产品推荐

