[英]How to use jenkins plugin for username with password in dsl?
I'm new to jenkins and I'm trying to use the credentials in a dsl using the credentials plugin我是 jenkins 的新手,我正在尝试使用凭证插件在 dsl 中使用凭证
template.xml模板.xml
<com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl>
<scope>GLOBAL</scope>
<id>PROD</id>
<description>prod credentials</description>
<username>prod</username>
<password>{{ encrypted_password_prod }}</password
</com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl>
I have defined the credentials in jenkins as username with password.我已将 jenkins 中的凭据定义为带密码的用户名。 the above encrypted value is saved in ansible.上述加密值保存在 ansible 中。
My question is how should i call them in my dsl我的问题是我应该如何在我的 dsl 中调用它们
Map credentials = [:]
credentialsBinding {
credentials.each { key, value ->
string("${key}", "${value}")
}
.credentials(["TF_VAR_username": "PROD" ,"TF_VAR_password" : "password_prod"])
Error:错误:
22:11:16 FATAL: Credentials 'PROD' is of type 'Username with password' where 'org.jenkinsci.plugins.plaincredentials.StringCredentials' was expected 22:11:16 致命:凭据“PROD”的类型为“带密码的用户名”,其中预期为“org.jenkinsci.plugins.plaincredentials.StringCredentials”
You can put credentials in Jenkins keystore (Jenkins -> Credentials -> System -> Global credentials -> Add Credentials), and then refer to them in your pipeline using withCredentials block like this:您可以将凭据放入 Jenkins 密钥库(Jenkins -> 凭据 -> 系统 -> 全局凭据 -> 添加凭据),然后使用 withCredentials 块在管道中引用它们,如下所示:
node {
withCredentials([usernameColonPassword(credentialsId: 'mylogin', variable: 'USERPASS')]) {
sh '''
set +x
curl -u "$USERPASS" https://private.server/ > output
'''
}
}
More info here: https://jenkins.io/doc/pipeline/steps/credentials-binding/更多信息在这里: https://jenkins.io/doc/pipeline/steps/credentials-binding/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.