Getting Error when I try to build image with Kaniko

I’m getting error building image: GET https://harbor.xxxx.useast1.master.xxxxxx.com/v2/devops/jvmrunner-openjdk8/manifests/edge: UNAUTHORIZED: authentication required; [map[Action:pull Class: Name:devops/jvmrunner-openjdk8 Type:repository]]

Extra Details:
Gitalb - self hoster on EC2 Instance, version 13.11
Gitlab Runner- installed on EKS using Helm chart

This is the .gitlab-ci.yaml file
build_kaniko_command:
stage: build
variables:
# To push to a specific docker tag other than latest(the default), amend the --destination parameter, e.g. --destination $CI_REGISTRY_IMAGE:$CI_BUILD_REF_NAME
# See Predefined variables reference | GitLab for available variables
IMAGE_DESTINATION: ${CI_REGISTRY_IMAGE}
image:
# We recommend using the CERN version of the Kaniko image: gitlab-registry.cern.ch/ci-tools/docker-image-builder
name: Google Cloud Platform
entrypoint: [""]
script:
# Prepare Kaniko configuration file
- echo “{“auths”:{”$HARBOR_HOST":{“username”:"$HARBOR_USER",“password”:"$HARBOR_PASSWORD"}}}" > /kaniko/.docker/config.json
# Build and push the image from the Dockerfile at the root of the project.
- /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/service/Dockerfile.codebuild --no-push
# Print the full registry path of the pushed image
- echo “Image pushed successfully to ${IMAGE_DESTINATION}”

Never Mind I got the solution. I try to delete the post but I’m unable to do that

Hi, better would be to post the solution, so that if other people experience it, they will find your post and know how to solve it. By posting your solution you help others also, which is a good thing.

1 Like

Here is the solution:

I provided variables HARBOR_HOST, HARBOR_USER, HARBOR_PASSWORD under project → settings -->CI/CD.

GitLab CI job unable to read those variable just because those variables have protect variable Flag turned on. if this flag turned on, variables will be rendered only on master branch.

so all you need to do is uncheck protect variable option so that it works for feature branches as well

1 Like