skip to Main Content

Life is great as I have 2 Gitlab CI projects that should both push docker images to the same directory and both have the some configuration but one is working, one is not…

Working:

push_gcp:
  only:
    - master
  image: docker:dind
  before_script:
    - docker login registry.gitlab.com -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD}
    - echo $GCLOUD_SERVICE_ACCOUNT_BASE64 > gcloud-service-key.txt
    - cat gcloud-service-key.txt | docker login -u _json_key_base64 --password-stdin https://europe-west4-docker.pkg.dev
  script:
    - ...
  after_script:
    - docker logout ${CI_REGISTRY}
    - docker logout https://europe-west4-docker.pkg.dev
  stage: push
  allow_failure: false
  tags: 
    - docker

enter image description here

Failing:

push_gcp:
  only:
    - master
  image: docker:dind
  before_script:
    - docker login registry.gitlab.com -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD}
    - echo $GCLOUD_SERVICE_ACCOUNT_BASE64 > gcloud-service-key.txt
    - cat gcloud-service-key.txt | docker login -u _json_key_base64 --password-stdin https://europe-west4-docker.pkg.dev
  script:
    - ...
  after_script:
    - docker logout ${CI_REGISTRY}
    - docker logout https://europe-west4-docker.pkg.dev
  stage: push_image
  allow_failure: false
  tags: 
    - docker

enter image description here

Any ideas? I’m going mental here..

2

Answers


  1. Chosen as BEST ANSWER

    A bit late but the solution was to disable protected variables in Gitlab CI/CD settings.


  2. Try this:

     - echo $GCP_SA_KEY > ${HOME}/gcloud-service-key.json
     - docker login -u _json_key --password-stdin https://gcr.io < ${HOME}/gcloud-service-key.json
    

    basically after --password-stdin, use < .

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search