3

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?

  • source the user configuration inside your jenkins build script. source ~/.bash_profile from there, you should be able to see the config/credentials files – crsuarezf Jan 30 '18 at 21:31
2

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

  • I added this to the ./profile file, and ran source to ensure that the file is read. However, this didn't solve the issue of the “Unable to locate credentials” error – fuzzi Apr 17 '18 at 19:25
0

Kindly update you aws credentials within the the bash of the jenkins server. Run the below commands:

# sudo -su jenkins
# aws configure

Reference Link: http://docs.aws.amazon.com/systems-manager/latest/userguide/sysman-ami-jenkins.html

  • My jenkins user has no HOME so it tries to save aws on the user I used when I run `sudo. Error: Permission denied: '/home/ubuntu/.aws/credentials – Karim N Gorjux Jul 27 '17 at 4:51
  • I also got the Error: Permission denied: '/home/ubuntu/.aws/credentials – fuzzi Apr 17 '18 at 14:50
  • I updated the permissions so that the jenkins user can read the file. However, now it throws a "Unable to locate credentials. " When I run "aws configure" the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY are saved there already. – fuzzi Apr 17 '18 at 16:04

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.