Jenkins 秘密文本凭证作为管道脚本中的变量

Vij*_*esh 5 jenkins ansible jenkins-pipeline

我创建了一个test_cred秘密文本类型的凭证来存储密码,该密码应该传递给 ansible 剧本。我将此参数作为额外变量传递root_pass给 ansible,但该值root_pass被评估为字符串test_cred而不是其中包含的秘密文本。有人可以帮助获取凭证的值,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}"
                ]
            )
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

Vij*_*esh 9

谢谢Zeitounator。工作代码是:

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}"
                ]
            )
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)