admin管理员组

文章数量:1391975

I'm new to Jenkins (version 2.492.2 on Windows) and cannot seem to get access to the password from withCredentials via the shell/environment variable.

I’ve tried a few variations in the snippet below. From everything I see, my environment/shell variable (at the process level) is being set to “*** Not Valid For Display ***”, so no matter how I access it from with the script, the actual password isn’t there.

Though this snippet doesn't show it, my goal is to pass the password to Powershell function within the pwsh{} block.

pipeline {
    agent any
    stages {
        stage('Cred Test') {
            steps {
                withCredentials([usernamePassword(credentialsId: 'xxxx', passwordVariable: 'impersonation_userpw', usernameVariable: 'impersonation_username')]) {
                    pwsh(returnStdout: true, script: '''
                        
                        $pw = $env:impersonation_userpw
                        Write-Warning "# $pw"

                        Write-Host $(Get-ChildItem Env: | %{
                            $len = [Math]::Min(10,$_.Value.Length)
                            "{0}`t{1}....`r`n" -f $_.Name,$_.Value.substring(0,$len)}
                        )

The variable dump in that script emits:

 HUDSON_HOME    C:\data\Je....
 HUDSON_SERVER_COOKIE   015d679e37....
 HUDSON_URL http://loc....
 impersonation_username svc-se......
 impersonation_userpw   *** Not Va....
 JAVA_HOME  C:\Program....
 JENKINS_HOME   C:\data\Je....
 JENKINS_NODE_COOKIE    4573f16f-0....
 JENKINS_SERVER_COOKIE  durable-bf....
 JENKINS_URL    http://loc....
 JOB_BASE_NAME  Pipeline D....

本文标签: withCredentials Credential Variable Injection and Interpolation in Jenkins on WindowsStack Overflow