下面是我尝试使用 gitlab-ci 执行的简单脚本。
image:
name: docker:latest
stages:
- build
services:
- docker:dind
- registry.gitlab.com/gitlab-org/cloud-deploy/aws-base:v0.3.6
Build:
stage: build
services:
- registry.gitlab.com/gitlab-org/cloud-deploy/aws-base:latest
script:
- aws s3 ls
我收到错误
Using docker image sha256:114405a05c1ea1579eada94100ea1262ec351ce96625fed47684ed05ef48f52f for docker:latest with digest docker@sha256:0752ca4e936da012c173c119217c0f9599b3b191c1557e53206d5d06d2627580 ...
/bin/sh: eval: line 137: aws: not found
我哪里出错了?
看起来脚本阶段的命令是在 Gitlab Runner 本身上运行,而不是在
aws-base
图像内。
要在容器映像内运行命令
aws s3 ls
aws-base:v0.3.6
您还应该在舞台内定义映像注册表。
image: registry.gitlab.com/gitlab-org/cloud-deploy/aws-base:v0.3.6
图像定义阶段之后应该是这样的:
Build:
stage: build
image: registry.gitlab.com/gitlab-org/cloud-deploy/aws-base:v0.3.6
services:
- registry.gitlab.com/gitlab-org/cloud-deploy/aws-base:latest
script:
- aws s3 ls
要使用 aws-base 映像,请确保您已在 CI/CD Secrets/Variables 中配置了
AWS_ACCESS_KEY_ID
、AWS_SECRET_ACCESS_KEY
、AWS_DEFAULT_REGION
变量