How to get username password stored in Jenkins credentials separately in jenkinsfile
Here is a tiny bit simpler version of StephenKing's answer
withCredentials([usernamePassword(credentialsId: 'mycreds', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
sh 'cf login some.awesome.url -u $USERNAME -p $PASSWORD'
}
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'
}