打印詹金斯凭证 ID

Printing jenkins credentials Id

有谁知道如何打印存储在 jenkins 中的凭据? 下面的脚本抛出:

Unexpected exception caught! groovy.lang.MissingPropertyException: No such property: crd for class: com.test.File

这是我的代码:

service.groovy

withCredentials([usernamePassword(
    credentialsId: vaultCredentialId, usernameVariable: 'ID', passwordVariable: 'CRED')]){


sh """
    crd=${CRED}
    for chars in `echo $crd | fold -w1`; do echo "value: $chars" ; done
"""

'withCredentials' 步骤将屏蔽任何与其秘密匹配的输出,所以如果你想显示它们,你必须在步骤之外进行。

pipeline {
    agent {
        label "master"
    }
    
    stages {
        stage("run") {
            steps {
                script {
                    userVar = null
                    passVar = null
                    withCredentials([usernamePassword(credentialsId: 'administrator-jenkins', passwordVariable: 'password', usernameVariable: 'username')]) {
                        userVar = username
                        passVar = password
                    }
                    echo "Username: ${userVar}"
                    echo "Password: ${passVar}"
                }
            }
        }
    }
}