If the gitlab container registry is hosted on your company's gitlab instance, and it cannot be accessed from the public network. Then it will not be accessible from the cloud hosted agents.
You were using the cloud hosted agent ubuntu-latest
in above pipeline. So you would see above error, since your gitlab container registry cannot be reached from microsoft network.
In this case, You will need to create self-hosted agents on the your company's machines that can access to the gitlab container registry within your company's network. And then you can specify the pipeline to run the self-hosted agents by targeting the pool to your private agent pool.
stages:
- stage: Build
displayName: Build image
jobs:
- job: Build
displayName: Build
#Targeting your private agent pool eg. default
pool: default
Please check out the detailed steps here to create self-hosted agents.
Update:
If the gitlab container registry can be accessed from public network. Please check if the registry url and password are all correctly setup.
Please try changing the Docker registry
in the ADO service connection to https://our_company_registry
. eg. https://gitlab.example.com
If all the settings are correctly setup. But the error still occurs. Please have a try building and pushing your image using docker commands in a script task. see below:
Note: Variables REGISTRY_USER
, REGISTRY_URL
need to be defined in your pipeline. Variable Password
needs to be defined as 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)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…