How to load AWS credentials into Jenkins DSL?

I have the following DSL structure:

freeStyleJob { wrappers { credentialsBinding { [ $class:"AmazonWebServicesCredentialsBinding", accessKeyVariable: "AWS_ACCESS_KEY_ID", credentialsId: "your-credential-id", secretKeyVariable: "AWS_SECRET_ACCESS_KEY" ] } } steps { // ACCESS AWS ENVIRONMENT VARIABLES HERE! } } 

However, this does not work. What is the correct syntax? For Jenkins pipelines, you can:

 withCredentials([[ $class: "AmazonWebServicesCredentialsBinding", accessKeyVariable: "AWS_ACCESS_KEY_ID", credentialsId: "your-credential-id", secretKeyVariable: "AWS_SECRET_ACCESS_KEY"]]) { // ACCESS AWS ENVIRONMENT VARIABLES HERE! } 

but this syntax does not work in a normal DSL groovy job.

tl; dr How can I export AWS credentials defined by the AmazonWebServicesCredentialsBinding plugin to environment variables in a Groovy DSL job? (NOT A TYPICAL PLUG SYNTACISIS!)

+5
source share
2 answers

I found a solution to solve this problem:

 wrappers { credentialsBinding { amazonWebServicesCredentialsBinding { accessKeyVariable("AWS_ACCESS_KEY_ID") secretKeyVariable("AWS_SECRET_ACCESS_KEY") credentialsId("your-credentials-id") } } } 

This will lead to the desired result.

+4
source

I cannot reuse the Miguel solution (even with the aws-credentials plugin installed), so here is another approach with the DSL configuration block

  configure { project -> def bindings = project / 'buildWrappers' / 'org.jenkinsci.plugins.credentialsbinding.impl.SecretBuildWrapper' / 'bindings' bindings << 'com.cloudbees.jenkins.plugins.awscredentials.AmazonWebServicesCredentialsBinding' { accessKeyVariable("AWS_ACCESS_KEY_ID") secretKeyVariable("AWS_SECRET_ACCESS_KEY") credentialsId("credentials-id") } } 
0
source

Source: https://habr.com/ru/post/1270148/


All Articles