我想弄清楚如何建立到我们公司的 gitlab 实例的服务连接,以便在 gitlab 容器注册表上构建和推送一些 docker 镜像
我创建了一个 docker registry 类型的服务连接,如下所示:
https://our_company_registry/project_name
read_registry
和 write_registry
权限Gitlab_Registry
我的天蓝色管道是
trigger:
- test
resources:
- repo: self
variables:
tag: '$(Build.BuildId)'
name: $(Date:yyyyMMdd)$(Rev:.r)
stages:
- stage: Build
displayName: Build image
jobs:
- job: Build
displayName: Build
pool:
vmImage: 'ubuntu-latest'
steps:
- task: Docker@2
displayName: Login to Gitlab_Registry
inputs:
command: login
containerRegistry: 'Gitlab_Registry'
- task: Docker@2
displayName: Build and push MyProject
inputs:
command: buildAndPush
repository: 'myproject'
containerRegistry: 'Gitlab_Registry'
dockerfile: '$(Build.SourcesDirectory)/src/MyProject/Dockerfile'
buildContext: '$(Build.SourcesDirectory)'
tags: '$(Build.BuildNumber)'
(我什至不太确定登录步骤...)
在 devops 中,构建成功,但我在何时推送映像时出现此错误
denied: requested access to the resource is denied
##[error]denied: requested access to the resource is denied
##[error]The process '/usr/bin/docker' failed with exit code 1
我错过了什么?
答案 0 :(得分:0)
如果 gitlab 容器注册表托管在您公司的 gitlab 实例上,并且无法从公共网络访问。那么它将无法从云托管代理访问。
您在上述管道中使用了云托管代理 ubuntu-latest
。所以你会看到上面的错误,因为你的 gitlab 容器注册表无法从微软网络访问。
在这种情况下,您需要在您公司的机器上创建自托管代理,这些代理可以访问您公司网络内的 gitlab 容器注册表。然后,您可以通过将 pool 定位到您的私有代理池来指定运行自托管代理的管道。
stages:
- stage: Build
displayName: Build image
jobs:
- job: Build
displayName: Build
#Targeting your private agent pool eg. default
pool: default
请查看 detailed steps here 以创建自托管代理。
更新:
如果可以从公共网络访问gitlab容器注册表。请检查注册网址和密码是否设置正确。
请尝试将 ADO 服务连接中的 Docker registry
更改为 https://our_company_registry
。例如。 https://gitlab.example.com
如果所有设置都正确设置。但错误仍然发生。请尝试在脚本任务中使用 docker 命令构建和推送您的图像。见下文:
注意:需要在管道中定义变量 REGISTRY_USER
、REGISTRY_URL
。变量 Password
需要定义为 secret variable。
- bash: |
docker login -u $(REGISTRY_USER) -p $REGISTRY_PASSWORD $(REGISTRY_URL)
docker build -t $(REGISTRY_URL)/group/project/image:latest .
docker push $(REGISTRY_URL)/group/project/image:latest
displayName: 'Bash Script'
env:
REGISTRY_PASSWORD: $(Password)