Unable to use AWS CLI in Jenkins due to “Unable to locate credentials” error

amazon-web-servicesJenkins

I am using Jenkins for CI. I need to be able to pull a file from an S3 bucket. Inside the jenkins job I do the following diagnostic from the jenkins shell:

cd ~

this takes me to /var/lib/jenkins

whoami

this returns the user jenkins

inside /var/lib/jenkins I have my .aws folder with the config and credentials file, yet when I run

aws configure list

I get this:

      Name                    Value             Type    Location
      ----                    -----             ----    --------
   profile                <not set>             None    None
access_key                <not set>             None    None
secret_key                <not set>             None    None
    region                <not set>             None    None

There is nothing there even though I have the .aws folder and the correct information in those two files. I originally tried placing the .aws folder in /home/jenkins but that didn't work either.

So, how do I get jenkins to actually work with the aws cli?

Best Answer

You can export the credentials as environmental variables:

$ export AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE
$ export AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
$ export AWS_DEFAULT_REGION=us-west-2

See http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html for more information. Depending on how you're using Jenkins you may want to use the EvnInject Plugin

Related Topic