Code quality template is not working in kubernetes

Summary

Cannot use the gitlab-ci.yml template for code quality on runners deployed on kubernetes.

https://gitlab.com/gitlab-org/gitlab-ce/blob/master/lib/gitlab/ci/templates/Jobs/Code-Quality.gitlab-ci.yml#L6

Because of [ -z "$DOCKER_HOST" -a "$KUBERNETES_PORT" ] DOCKER_HOST is not getting assigned, so build fails with:

docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock

Steps to reproduce

  1. Setup a gitlab runner on [kubernetes]
  2. add Code Quality job to the gitlab-ci.yml
  3. Run the pipeline

What is the current bug behavior?

Actual results: See above

What is the expected correct behavior?

Expected results: code quality job runs successfully

Possible fixes

Removing KUBERNETES_PORT from the construction solves the issue.

@rickywiens has made a hypothesis that #9784 (closed) may fix this issue. That needs to be dealt with for other reasons so afterwards we will re-evaluate this issue to see if it is resolved and if not schedule further investigation.

Edited by James Liu