Reputation: 624
Below is my YML file structure. I want the following up stages to be run without reinitializing the git repository. The git repository should only be initialized during the first stage, which is the build stage.
variables:
GIT_STRATEGY: fetch
stages:
- build
- run_test
- run_test2
build_job:
variables:
test_env: "test"
stage: build
script:
- "powershell -File ./Scripts/BuildSolution.ps1"
only:
refs:
- TDD-G2
run_test:
variables:
test_env: "test"
stage: run_test
script:
- "powershell -File ./Project1/scripts/RunSelenium.ps1"
artifacts:
when: always
paths:
- ./Project1/TestResults
run_test2:
variables:
test_env: "test"
stage: run_test2
script:
- "powershell -File ./Project2/scripts/RunSelenium.ps1"
artifacts:
when: always
paths:
- ./Project2/TestResults
Upvotes: 22
Views: 21288
Reputation: 67
if in any of your jobs you store an artifact or make any changes inside the git initialized repository, it will be removed in the subsequent jobs due to the default GIT_STRATEGY
reinitializing git during every single job run. setting GIT_CLEAN_FLAGS
to none
will keep your local copy safe but would still fetch and initialize the repo.
i did not find any of the above answers appealing, for in my use case, i needed to maintain my local version of the project exactly the same, throughout the entire pipeline without pulling or pushing any changes back. setting GIT_STRATEGY: none
in subsequent jobs helped skip all the git operations giving me exactly what i want.
Upvotes: 0
Reputation: 1466
This is what you are looking for:
job1:
variables:
GIT_CHECKOUT: "false"
Use that variable in the job where you want to skip checking out the repo. Make sure the GIT_STRATEGY you are using on your project on GitLab is either 'clone' or 'fetch', otherwise it won't work.
Reference: https://docs.gitlab.com/ee/ci/runners/configure_runners.html#git-checkout
Upvotes: 4
Reputation: 413
You could use the variable GIT_CLEAN_FLAGS
to instruct the gitlab-runner to call git clean
in a constrained way. For example, by specifying none
, you could disable calling git clean
alltogether, so files produced by the previous stage won't be deleted.
run_test:
variables:
test_env: "test"
GIT_CLEAN_FLAGS: none
https://docs.gitlab.com/ee/ci/runners/configure_runners.html#git-clean-flags https://docs.gitlab.com/ee/ci/large_repositories/#git-clean-flags
Upvotes: 9
Reputation: 2582
I was facing quite similar problem and where I had three stage's build, test and deploy. In deploy stage i wanted to create a tag something like But I was facing a strange issue where even after deleting the tag from remote (Note: i was working alone on this project) the pipeline was failing continuously saying the tag already exists. But after some time the same job completed successfully.
To fix this I set the strategy to clone
(Explained below) only for deploy(Git repository was reinitializing again here) job but for build and test it is fetch(default option). As
variables:
GIT_STRATEGY: clone
For GitLab:
Git strategy
Introduced in GitLab Runner 8.9.
By default, GitLab is configured to use the fetch Git strategy, which is recommended for large repositories. This strategy reduces the amount of data to transfer and does not really impact the operations that you might do on a repository from CI.
There are two options. Using:
Hope it help to someone who came to this issue.
Upvotes: 11