How to skip 'Reinitialized existing Git repository' on Gitlab CICD Stage

Viewed 7047

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
2 Answers

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:

  • git clone: which is slower because it clones the repository from scratch for every job
  • git fetch: which is default in GitLab and faster as it re-uses the local working copy (falling back to clone if it doesn’t exist). This is recommended, especially for large repositories.

Detail Read is here and here

Hope it help to someone who came to this issue.

Related