Skip to content

Add custom clone path for the build

What does this MR do?

Add custom clone path for the build

When the user specifies CI_PROJECT_DIR environment variable inside of the .gitlab-ci.yml if the path is valid it is used to clone and build.

CI_PROJECT_DIR takes precedence over the configured build dir and the default build dir.

This is not available when shared dir are enabled meaning:

  • Docker executor has a mounted volume
  • Shell executor
  • SSH executor

Closes #2211 (closed)

Implementation Reasons

CI_PROJECT_DIR was a variable that already exists where the full path of the repository is cloned and where the job is run. Allowing the user to define this and use it seems like the least amount of code changes and something the users are already used/familiar with.

Another option is to introduce the git key when you define a stage. Where the clone key defines which directory the runner should use to clone and build. In theory, we could reuse git key for future git customization we might want. Adding the key seems like adding extra complexity to using the runner, one more key to document, show how the user to use it and more configuration point the user has to keep track of. Also, this would have to be defined at every stage whilst the CI_PROJECT_DIR can be defined once under the variables key you want it across all stages.

build:
    image: golang:1.10-alpine3.7
    stage: build
    script:
        - go build -v -o app
    git:
      clone: "/go/src/gitlab.com/gitlab.org/gitlab-runner"

Why was this MR needed?

Some builds require the code to be checked out in a specific directory, such as GO it requires you to have your code in the specified $GOPATH. The usual way to solve this is to either symlink to the desired directory or move the directory as explained in #2211 (closed).

Allowing the user to specify which directory the code needs to be cloned and build will help prevent this and other issues like this one

Are there points in the code the reviewer needs to double check?

  • Shared directory, to my knowledge if it is running on an executor with shared directories a unique directory for each build needs to be created to prevent conflicts. Is this true?

How to Test

Below is a simple gitlab-ci.yml file to help manually testing

image: golang:1.10-alpine3.7

variables:
  CI_PROJECT_DIR: /go/src/gitlab.com/test-namespace/2211-custom-clone-path

stages:
    - test

dir:
    stage: test
    script:
      - pwd
      - ls -la /go/src/gitlab.com/test-namespace/2211-custom-clone-path

Questions

BLOCKERS

Blocked by:

Does this MR meet the acceptance criteria?

  • Documentation created/updated gitlab-org/gitlab-ce!19664 (the old, reverted one)
  • Documentation created/updated: gitlab-ce!20427
  • Tests
    • Added for this feature/bug
    • All builds are passing
  • Branch has no merge conflicts with master (if you do - rebase it please)

What are the relevant issue numbers?

Closes #2211 (closed)

Edited by Tomasz Maczukin

Merge request reports

Loading