Jenkins Credentials Store Access via Groovy

后端 未结 3 789
长情又很酷
长情又很酷 2021-01-31 09:35

I have found a way to access the credentials store in Jenkins:

def getPassword = { username ->
    def creds = com.cloudbees.plugins.credentials.CredentialsPr         


        
3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-31 10:23

    If you just want to retrieve the credentials for a given credentials ID, the simplest way is to use the withCredentials pipeline step to bind credentials to variables.

    withCredentials([usernamePassword( credentialsId: 'myCredentials', 
                         usernameVariable: 'MYUSER', passwordVariable: 'MYPWD' )]) { 
        echo "User: $MYUSER, Pwd: $MYPWD" 
    }
    

提交回复
热议问题