Gitlab运行程序无法运行AWS命令

时间:2019-06-13 09:54:54

标签: amazon-web-services gitlab gitlab-ci gitlab-ci-runner

我正在尝试使用共享的Runner运行GitLab的工作,
我创建了一个@Version private Integer version; 并将其保留在项目的根目录下,
将AWS信誉配置为环境变量-

.gitlab-ci.yml

AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_DEFAULT_REGION enter image description here

仔细检查了我要从中建立的分支是Settings -> CI / CD -> Variables

以下是我的.gitlab-ci.yml-

protected

CICD脚本具有aws命令-

stages:
    - build

build:
    image: python:latest
    stage: build
    script:
            - apt-get update
            - apt-get install -y zip unzip
            - pip install awscli
            - mkdir ~/.aws/
            - touch ~/.aws/credentials
            - pip install awscli
            - printf "[eb-cli]\naws_access_key_id = %s\naws_secret_access_key = %s\nregion = %s\n" "$AWS_ACCESS_KEY_ID" "$AWS_SECRET_ACCESS_KEY" "$AWS_DEFAULT_REGION" >> ~/.aws/credentials
            - bash cicdScript.sh

但是我仍然收到以下错误-

$(aws s3 ls)

参考-
https://medium.com/faun/continuous-static-upload-to-aws-s3-using-gitlab-runners-17f0260a5af2

2 个答案:

答案 0 :(得分:1)

您可以使用

- pip install awscli
- aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID
- aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY
- aws configure set region $AWS_DEFAULT_REGION

代替

- mkdir ~/.aws/
- touch ~/.aws/credentials
- pip install awscli
- printf "[eb-cli]\naws_access_key_id = %s\naws_secret_access_key = %s\nregion = %s\n" "$AWS_ACCESS_KEY_ID" "$AWS_SECRET_ACCESS_KEY" "$AWS_DEFAULT_REGION" >> ~/.aws/credentials

答案 1 :(得分:0)

在您的代码中,您的凭据的配置文件设置为“eb-cli”

printf "[eb-cli]\naws_access_key_id = %s\naws_secret_access_key = %s\nregion = %s\n" "$AWS_ACCESS_KEY_ID" "$AWS_SECRET_ACCESS_KEY" "$AWS_DEFAULT_REGION" >> ~/.aws/credentials

你应该使用的命令是

aws s3 ls --profile eb-cli

如果您不通过配置文件,则会选择 [默认]。由于未配置默认值,因此导致了问题。