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
- Should we update gitlab-ci.yml templates to reflect this change?
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)
Merge request reports
- version 229285b8ed
- version 21175f2a3c
- version 20175f2a3c
- version 194f4d9f47
- version 189f3be73b
- version 179f3be73b
- version 16bfd6902a
- version 15c375a99f
- version 147ccecd1c
- version 13a46f3633
- version 1227442e07
- version 112696d4cb
- version 104ebb6feb
- version 9e667be8c
- version 89bdd4950
- version 7f0e13059
- version 6053149a5
- version 5b67f3ef6
- version 456743f79
- version 39f8d181c
- version 2b54b2630
- version 1fa12a5c0
- master (base)
- latest version38c08e223 commits,
- version 229285b8ed3 commits,
- version 21175f2a3c2 commits,
- version 20175f2a3c2 commits,
- version 194f4d9f473 commits,
- version 189f3be73b2 commits,
- version 179f3be73b2 commits,
- version 16bfd6902a1 commit,
- version 15c375a99f3 commits,
- version 147ccecd1c2 commits,
- version 13a46f36339 commits,
- version 1227442e078 commits,
- version 112696d4cb8 commits,
- version 104ebb6feb7 commits,
- version 9e667be8c6 commits,
- version 89bdd49505 commits,
- version 7f0e130594 commits,
- version 6053149a53 commits,
- version 5b67f3ef62 commits,
- version 456743f791 commit,
- version 39f8d181c1 commit,
- version 2b54b26301 commit,
- version 1fa12a5c01 commit,
- Side-by-side
- Inline