How to dynamically pass credentials for Jenkins
Is there a way to dynamically pass the credentialsId in the Jenkins pipeline in the withCredentials block using an environment variable?
This currently works:
withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', credentialsId: 'my-aws-credentials',
ACCESS_KEY: 'ACCESS_KEY', SECRET_KEY: 'SECRET_KEY']]) { }
But this is not the case:
withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', credentialsId: '${AWS_CREDENTIAL_ID}',
ACCESS_KEY: 'ACCESS_KEY', SECRET_KEY: 'SECRET_KEY']]) { }
I should add that builds are done in a docker container, but other environment variables work fine, so I expect this to work too.
+3
source to share