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?

1
  • 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, 2018 at 21:31

5 Answers 5

3

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

2
  • 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, 2018 at 19:25
  • Not working for me. Still unable to find credentials.
    – Jimmy
    Apr 4, 2019 at 11:18
2

This method worked for me:

  1. Make directory in /var/lib/jenkins that called .aws (or copy .aws folder from home directory if you already configured your aws credentials via "aws configure" command)
  2. Then go down to /var/lib/jenkins/.aws and write sudo shown -R jenkins ./ to change owner for files in .aws directory.
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

3
  • 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 Jul 27, 2017 at 4:51
  • I also got the Error: Permission denied: '/home/ubuntu/.aws/credentials
    – fuzzi
    Apr 17, 2018 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, 2018 at 16:04
0

There's a similar problem that jenkins can't find credential small node program running by some bat. I've solved by changing home directory of jenkins which could be edited on jenkins configuration page into where the '.aws' folder is. (I've been configured the aws setting directly via remote desktop app)

0

If you are seeing this issue within corporate network while using instance role then please make sure the proxy settings are correct.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .