0
votes

I have GitLab running on computer A, development environment (Visual studio Pro) on computer B and Windows Server on computer C.
I set up GitLab-Runner on computer C (Windows server). I also set up .gitlab-ci.yml file to perform build and run tests for ASP.NET Core application on every commit.

I don't know how can I get code on computer C (Windows server) so I can build it (dotnet msbuild /p:Configuration=Release "%SOLUTION%"). It bothers me that not a single example .gitlab-ci.yml I found on net, doesn't pull code form GitLab, before building application. Why?

Is this correct way to set-up CI/CD:

  • User create pull request (a new branch is created)
  • User writes code
  • User commit code to branch from computer B.
  • GitLab runner is started on computer C.
  • It needs to pull code from current branch (CI_COMMIT_REF_NAME)
  • Build, test, deploy ...

Should I use common git command to get the code, or is this something GitLab runner already do? Where is the code?

Why no-one pull code from GitLab in .gitlab-ci.yml?

Edited:

I get error

'"git"' is not recognized as an internal or external command

. Solution in my case was restart GitLab-Runner. Source.

@MilanVidakovic explain that source is automatically downloaded (which I didn't know). I just have one remaining problem of how to get correct path to my .sln file.
Here is my complete .gitlab-ci.yml file:

variables:
    SOLUTION: missing_path_to_solution           #TODO

before_script:
    - dotnet restore

stages:
    - build

build:
    stage: build
    script:
        - echo "Building %CI_COMMIT_REF_NAME% branch."
        - dotnet msbuild /p:Configuration=Release "%SOLUTION%"
    except:
        - tags

I need to set correct variable for SOLUTION. My dir (where GitLab-Runner is located) currently holds this folder/files:

- config.toml
- gitlab-runner.exe
- builds/
    - 7cab42e4/
        - 0/
            - web/                 # I think this is project group in GitLab
                - test/            # I think this is project name in GitLab
                    - .sln
                    - AND ALL OTHER PROJECT FILES      #Based on first look
                - testm.tmp

So, what are 7cab42e4, 0. Or better how to get correct path to my project structure? Is there any predefined variable?

Edited2: Answer is CI_PROJECT_DIR.

1

1 Answers

2
votes

I'm not sure I follow completely.

On every commit, Gitlab runner is fetching your repository to C:\gitlab-runner\builds.. on the local machine (Computer C), and builds/deploys or does whatever you've provided as an action for the stage.

Also, I don't see the need for building the source code again. If you're using Computer C for both runner and tests/acceptance, just let the runner do the building and add Artifacts item in your .gitlab-ci.yaml. Path defined in artifacts will retain your executables on Computer C, which you are then able to use for whatever purposes.

Hope it helps.

Edit after comment:

When you push to repository, Gitlab CI/CD automatically checks your root folder for .gitlab-ci.yaml file. If its there, the runner takes over, parses the file and starts executing jobs/stages.

As soon as the file itself is valid and contains proper jobs and stages, runner fetches the latest commit (automatically) and does whatever script item tells it to do.

To verify that everything works correctly, go to your Gitlab -> CI / CD -> Pipelines, and check out whats going on. You should see something like this: enter image description here

Maybe it would be best if you posted your .yaml file, there could be a number of reasons your runner is not picking up the code. For instance, maybe your .yaml tags are not matching what runner is created to pick up etc.