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


1 answer


Actually, I was able to solve it by doing this ->



withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', credentialsId: env.AWS_CREDENTIAL_ID,
                        ACCESS_KEY: 'ACCESS_KEY', SECRET_KEY: 'SECRET_KEY']]) { } 

      

+1


source







All Articles