在 Jenkins Job 中,我尝试使用脚本登录 WAS CLI:
eval $(echo $(aws ecr get-login --no-include-email --region=eu-north-1))
当我手动执行此操作时,一切正常。
$(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
但是当 Jenkins 尝试运行它时,我得到日志:
+ aws ecr get-login --no-include-email --region=eu-north-1 Unable to locate credentials.
You can configure credentials by running "aws configure".
问题的更代表性的观点是:
$ 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
如何为现有按键分配相同的按键访问权限以使用
jenkins
角色?
注意:不确定是否推荐,但这对我有用:
sudo -su jenkins
cd /var/lib/jenkins/
mkdir .aws
然后创建凭据和配置文件。
然后,如果您执行 aws configure list,它实际上不会显示添加的配置文件,但它在运行 junkins 作业时起作用。
另一种方法
在 /var/lib/jenkins 中创建名为 .aws 的目录(如果您已通过“aws configure”命令配置了 aws 凭证,则从主目录复制 .aws 文件夹)
然后进入 /var/lib/jenkins/.aws 并写入 sudo shown -R jenkins ./ 来更改 .aws 目录中文件的所有者。
您可以使用给定的命令再次检查:
aws 配置列表
我已经通过更改用户来修复它。 (前置要求:安装
awscli
,最新)
userabc$ sudo su
root$ su jenkins
jenkins$ aws configure
(但首先,需要在 IAM 上创建编程帐户,然后在 Jenkins 用户中配置 AWS 帐户)。