Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to skip Reinitialized existing Git repository on Gitlab CICD Stage

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
like image 738
mokh223 Avatar asked Oct 08 '20 04:10

mokh223


People also ask

How do I fix Reinitialized existing Git Repository?

Answers 2 : of UNDO Reinitialized existing Git repository Made a mistake. You can fix the existing local commit by staging all the fixes and then running git commit --ammed. Then, overwrite the remote branch by git push --force origin.

Does GitLab runner clone Repository?

GitLab and GitLab Runner perform a shallow clone by default.

How do I stop a running pipeline in GitLab?

To enable or disable GitLab CI/CD Pipelines in your project: Navigate to Settings > General > Visibility, project features, permissions. Expand the Repository section. Enable or disable the Pipelines toggle as required.

What is Git_strategy?

You can set the GIT_STRATEGY used for getting recent application code, either in the global variables section or the variables section for individual jobs. If left unspecified, the default from project settings will be used. There are three possible values: clone , fetch , and none .

When should the git repository be initialized?

The git repository should only be initialized during the first stage, which is the build stage. Show activity on this post. I was facing quite similar problem and where I had three stage's build, test and deploy.

What configuration options are available for GitLab CI/CD?

GitLab CI/CD supports numerous configuration options: Schedule pipelines to run as often as you need. Define a custom path for the CI/CD configuration file. Configure jobs for using Git submodules. Using SSH keys in your CI pipelines. Trigger pipelines through the API. Design a pipeline structure for running a pipeline in merge requests.

What happens if I disable GitLab CI/CD?

If you are using an external CI/CD server like Jenkins or Drone CI, it is advised to disable GitLab CI/CD in order to not have any conflicts with the commits status API. GitLab CI/CD is exposed via the /pipelines and /jobs pages of a project. Disabling GitLab CI/CD in a project does not delete any previous jobs.

How do I re-use a git repository?

If you ever want to reuse the old repository and its history, just rename the folder .git and then use the commands for a new start, either depending on the situation, if you have a remote repo your are starting from or if your local files are the starting point.


Video Answer


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.

like image 116
Dolly Avatar answered Oct 21 '22 19:10

Dolly


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

like image 32
Tamás Kovács Avatar answered Oct 21 '22 21:10

Tamás Kovács