[英]Jenkins secret text credential as variable in pipeline script
I have created a credential test_cred
of type secret text to store a password, which should be passed to an ansible playbook.我创建了一个秘密文本类型的凭据
test_cred
来存储密码,该密码应传递给 ansible 剧本。 I am passing this parameter as an extra variable root_pass
to ansible, but the value root_pass
is evaluated to string test_cred
instead of the secret text contained in it.我将此参数作为额外变量
root_pass
传递给 ansible,但值root_pass
被评估为字符串test_cred
而不是其中包含的秘密文本。 Can somebody please help to get the value of the credential test_cred
so that I can pass it to ansible.有人可以帮助获取凭证
test_cred
的值,以便我可以将其传递给 ansible。
stages {
stage('Execution') {
steps {
withCredentials([string(credentialsId: 'test_cred', variable: 'test')]) {
}
ansiblePlaybook(
installation: 'ansible',
inventory: "inventory/hosts",
playbook: "${PLAYBOOK}",
extraVars: [
server: "${params.Server}",
client: "${params.Client}",
root_pass: "${test}"
]
)
}
}
}
Thank you Zeitounator.谢谢 Zeitounator。 The working code is:
工作代码是:
stages {
stage('Execution') {
steps {
withCredentials([string(credentialsId: 'test_cred', variable: 'test')]) {
ansiblePlaybook(
installation: 'ansible',
inventory: "inventory/hosts",
playbook: "${PLAYBOOK}",
extraVars: [
server: "${params.Server}",
client: "${params.Client}",
root_pass: "${test}"
]
)
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.