gpt4 book ai didi

gitlab-ci - 推送构建图像时,Gitlab-runner 有 'access denied'

转载 作者:行者123 更新时间:2023-12-05 02:15:44 25 4
gpt4 key购买 nike

我在将带有 gitlab-runner 的构建镜像推送到 gitlab 存储库时遇到问题。

我的gitlab-ci.yml:

image: docker:latest
services:
- docker:dind

stages:
- build
- release

variables:
TEST_IMAGE: registry.gitlab.com/myhost/haproxy:$CI_COMMIT_REF_NAME
RELEASE_IMAGE: registry.gitlab.com/myhost/haproxy:latest

before_script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN gitlab.com

build:
stage: build
script:
- docker build --pull -t $TEST_IMAGE .
- docker push $TEST_IMAGE

release:
stage: release
script:
- docker pull $TEST_IMAGE
- docker tag $TEST_IMAGE $RELEASE_IMAGE
- docker push $RELEASE_IMAGE
only:
- master

docker 登录有效——我得到“登录成功”——但是当涉及到推送操作时,我得到:

$ docker push $TEST_IMAGE
The push refers to repository [registry.gitlab.com/myhost/haproxy]
d77ab2f42dd4: Preparing
c70258f465dd: Preparing
96b45c1aa07c: Preparing
28587e66f3e8: Preparing
21b59fc0e3a3: Preparing
9c46f426bcb7: Preparing
9c46f426bcb7: Waiting
denied: access forbidden
ERROR: Job failed: exit code 1

运行器在我自己的服务器上,我正在推送到 gitlab.com

我还检查了我的本地机器,在脚本中执行终端命令 - 登录、构建和推送 - 一切正常,但如果我在本地运行运行者,注册它并获得工作,我也会得到禁止访问错误。

所以我认为问题出在运行者身上,博什么。我比较了几个版本的 gitlab-runner 从 10.6 到最新的 11.0 的行为

有什么想法吗?

最佳答案

所以问题是错误的注册表地址 - 它应该是 registry.gitlab.com

它误导了我,即使没有“registry”前缀,它也会在终端中显示“已登录”,所以最好的解决方案是在 gitlab-ci.yml 登录期间使用内置变量:

docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY 

关于gitlab-ci - 推送构建图像时,Gitlab-runner 有 'access denied',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51321886/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com