[英]How to use credentialId to retrieve the username/password in my own jenkins plugin
[英]How to use jenkins plugin for username with password in dsl?
我是 jenkins 的新手,我正在嘗試使用憑證插件在 dsl 中使用憑證
模板.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>
我已將 jenkins 中的憑據定義為帶密碼的用戶名。 上述加密值保存在 ansible 中。
我的問題是我應該如何在我的 dsl 中調用它們
Map credentials = [:]
credentialsBinding {
credentials.each { key, value ->
string("${key}", "${value}")
}
.credentials(["TF_VAR_username": "PROD" ,"TF_VAR_password" : "password_prod"])
錯誤:
22:11:16 致命:憑據“PROD”的類型為“帶密碼的用戶名”,其中預期為“org.jenkinsci.plugins.plaincredentials.StringCredentials”
您可以將憑據放入 Jenkins 密鑰庫(Jenkins -> 憑據 -> 系統 -> 全局憑據 -> 添加憑據),然后使用 withCredentials 塊在管道中引用它們,如下所示:
node {
withCredentials([usernameColonPassword(credentialsId: 'mylogin', variable: 'USERPASS')]) {
sh '''
set +x
curl -u "$USERPASS" https://private.server/ > output
'''
}
}
更多信息在這里: https://jenkins.io/doc/pipeline/steps/credentials-binding/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.