Pavel
Pavel

Reputation: 2101

Jenkins can't use aws-cli key. Unable to locate credentials for AWS CLI

In Jenkins Job I'm trying to login to WAS CLI with a script:

eval $(echo $(aws ecr get-login --no-include-email --region=eu-north-1))

When I do it manually all works fine.

$(echo $(aws ecr get-login --no-include-email --region=eu-north-1))
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
WARNING! Your password will be stored unencrypted in /home/ubuntu/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded

But when Jenkins try to run it I get log:

+ aws ecr get-login --no-include-email --region=eu-north-1 Unable to locate credentials. 
You can configure credentials by running "aws configure".

More represented view of the problem is:

$ sudo -H -u ubuntu aws configure list
      Name                    Value             Type    Location
      ----                    -----             ----    --------
   profile                <not set>             None    None
access_key     ****************L7YQ shared-credentials-file
secret_key     ****************dr46 shared-credentials-file
    region               eu-north-1      config-file    ~/.aws/config


$ sudo -H -u jenkins aws configure list
      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

How to assign the same key access for use jenkins role to existed keys?

Upvotes: 1

Views: 4305

Answers (3)

abisec
abisec

Reputation: 51

Another method

  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.

  3. You can check again with the given command:

aws configure list

Upvotes: 1

Muhammad Jamee Ghouri
Muhammad Jamee Ghouri

Reputation: 139

I have fixed it by changing the user. (Pre-requirement: install awscli, latest)

userabc$ sudo su
root$ su jenkins
jenkins$ aws configure

(but first, programmatic account need to be created on IAM then configure AWS account in Jenkins users).

Upvotes: -1

james
james

Reputation: 152

Note: Not sure if it is recommended, but this worked for me:

sudo -su jenkins
cd /var/lib/jenkins/
mkdir .aws

then create credentials and config files.

then if you do aws configure list, it doesn't actually show the profiles added but it works while running the junkins job.

Upvotes: 4

Related Questions