Denied: access forbidden in gitlab cicd with .net 6

Dung Do Tien Dec 05 2021 153

Hello guys, I have a project with .Net 6 and using GtiLab cicd to help deploy project into docker linux ubuntu 20.04.

But i got an exception "denied: access forbidden"

 The push refers to repository [registry.gitlab.com/democicd/docker_cicd]
b5827c21e3b2: Preparing
2d87ec54eabf: Preparing
a4b9c6e7f8bb: Preparing
ba809ad0e044: Preparing
31bd36e157b6: Preparing
6185ed1ad590: Preparing
f5600c6330da: Preparing
6185ed1ad590: Waiting
f5600c6330da: Waiting
denied: access forbidden
Cleaning up project directory and file based variables
ERROR: Job failed: exit status 1

Below is my .gitlab-ci.yml

 image: docker:stable
services:
    - docker:dind 
    
stages:
  - build
  - deploy
#tet
democi_cd(build):
    stage: build
    tags:
        - build_testing
    script:
        - docker login registry.gitlab.com
        - docker build -t registry.gitlab.com/democicd/docker_cicd:latest . -f CICD.App/Dockerfile
        - docker push registry.gitlab.com/democicd/docker_cicd:latest
    only:
        - testing

Thank you for any solution for me!!

Have 1 answer(s) found.
  • J

    Javier Dec 05 2021

    You not have permistion to access registry, on your .gitlab-ci.yml you need to add more docker login. Syntax as below:

      docker login -u [your_username] -p [your_password] registry.gitlab.com

    You can add line code above into before_script of .gitlab-ci.yml to help login before run script. Like this:

     democi_cd(build):
        stage: build
        tags:
            - build_testing
        before_script:
            - docker login -u testcicd -p 123456 registry.gitlab.com
        script:
            - docker login registry.gitlab.com
            - docker build -t registry.gitlab.com/democicd/docker_cicd:latest . -f CICD.App/Dockerfile
            - docker push registry.gitlab.com/democicd/docker_cicd:latest
        only:
            - testing

    and it really worked for me. I hope it also solved for you.

Leave An Answer
* NOTE: You need Login before leave an answer

* Type maximum 2000 characters.

* All comments have to wait approved before display.

* Please polite comment and respect questions and answers of others.

Popular Tips

X Close