Support nested env variables for GIT_CLONE_PATH

Summary

When a user-specified GIT_CLONE_PATH that has the value and has nested environment variables it's not expanded properly and the validation fails

Steps to reproduce

.gitlab-ci.yml
image: golang:1.12

variables:
    GOPATH: $CI_BUILDS_DIR/go
    GIT_CLONE_PATH: $GOPATH/src/gitlab-org/gitlab-runner

test:
  stage: test
  script:
  - echo $CI_BUILDS_DIR
  - echo $GOPATH
  - echo $GIT_CLONE_PATH
  - pwd
  - ls -la

Actual behavior

Running with gitlab-runner development version (HEAD)
  on docker yj3uiViT
ERROR: Job failed: the GIT_CLONE_PATH="$CI_BUILDS_DIR/go/src/gitlab-org/gitlab-runner" has to be within "/builds" <- Notice how $GOPATH got expanded but then `CI_BUILD_DIR` did not, for the [string match](https://gitlab.com/gitlab-org/gitlab-runner/blob/3cf5d6d569a99fb08dac469940cd6b47a99f8e24/common/build.go#L170-173)

Expected behavior

The build to clone to the correct path

Relevant logs and/or screenshots

job log
Running with gitlab-runner development version (HEAD)
  on docker yj3uiViT
ERROR: Job failed: the GIT_CLONE_PATH="$CI_BUILDS_DIR/go/src/gitlab-org/gitlab-runner" has to be within "/builds"

Environment description

config.toml contents
[[runners]]
  name = "docker"
  url = "xxxx"
  token = "xxxxx"
  executor = "docker"
  [runners.docker]
    tls_verify = false
    image = "alpine:3.9"
    privileged = false
    disable_entrypoint_overwrite = false
    oom_kill_disable = false
    disable_cache = false
    volumes = ["/cache"]
    shm_size = 0
  [runners.cache]
    Type = "s3"
    Path = "path/to/prefix"
    Shared = true
    [runners.cache.s3]
    [runners.cache.gcs]

Used GitLab Runner version

All GitLab Runner versions that support GIT_CLONE_PATH

Possible fixes

ERROR: Job failed: the GIT_CLONE_PATH="$CI_BUILDS_DIR/go/src/gitlab-org/gitlab-runner" has to be within "/builds" <- Notice how $GOPATH got expanded but then CI_BUILD_DIR did not, for the string match We need to make sure we fully expand it before continuing it.

Edited Jun 26, 2019 by Steve Xuereb
Assignee Loading
Time tracking Loading