How to get username password stored in Jenkins credentials separately in jenkinsfile

前端 未结 2 649
抹茶落季
抹茶落季 2021-02-12 17:28

I\'ve stored username and password as credentials in jenkins. Now I would like to use them in my Jenkinsfile.

I am using withCredentials DSL, however, I\'m

2条回答
  •  渐次进展
    2021-02-12 17:59

    You can use the UsernamePasswordMultiBinding to get credential data in separate values:

    withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId:'mycreds',
      usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD']
    ])
    

    So the following should work in your case:

    withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId:'mycreds', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD']]) {
      sh 'cf login some.awesome.url -u $USERNAME -p $PASSWORD'
    }
    

提交回复
热议问题