CI/CD for .NET with GitLab Shell Executor (original) (raw)

Last Updated : 9 May, 2026

CI/CD for a .NET application using GitLab Shell Executor automates the build, test, and deployment process directly on the host machine for faster and consistent delivery.

Understanding CI/CD with GitLab

Before diving into implementation details, let's briefly review the concepts of CI/CD and how GitLab facilitates their implementation:

Requirements and Configuration

Essential tools and their paths required for setting up and executing the CI/CD pipeline.

GitLab Runner Set Up

Follow these steps to download, configure, and register GitLab Runner

**Step 1: Download and Setup

**Step 2: Check and Stop Runner

gitlab-runner status

gitlab-runner.exe stop

**Step 3: Register Runner

gitlab-runner.exe register

Provide the following details:

**Step 4: Start Runner

gitlab-runner start

**Step 5: Verify Runner

**Note: If the circle is gray, it means the runner has not started and starts again.

Windows GitLab Runner Command

Common commands used to manage and control the GitLab Runner service on Windows.

  1. **gitlab-runner.exe register: Register runner
  2. **gitlab-runner.exe start: Start runner
  3. **gitlab-runner.exe stop: Stop runner
  4. **gitlab-runner.exe status: Check status
  5. **gitlab-runner restart: Restart runner
  6. **gitlab-runner uninstall: Uninstall runner
  7. **gitlab-runner unregister --all-runners: Remove all runners

.gitlab-ci.yml Configuration

Defines CI/CD pipeline stages, jobs, and execution steps, including build, test, and deployment, along with scripts, variables, and dependencies.

Variables

variables:
NUGET_PATH: 'C:\Tools\Nuget\nuget.exe'
MSBUILD_PATH: 'C:\Program Files (x86)\Microsoft Visual Studio...\MSBuild.exe'
MSTEST_PATH: 'C:\Program Files (x86)\Microsoft Visual Studio...\mstest.exe'
TEST_FOLDER: '.\test\bin\Release'

Stages

stages:

Before Script

before_script:

Build Stage

Compiles the .NET solution using MSBuild to generate application binaries.

build_job:
stage: build
only:
- developer
script:
- '& "$env:MSBUILD_PATH" sourcecode\project.sln ...'

Test Stage

Executes automated tests (e.g., via MSTest) to validate the built application.

test_job:
stage: test
script:
- .\test\test.bat
dependencies:
- build_job

Deploy Stage

Copies or publishes the built artifacts to the target deployment directory or environment.

deploy_job:
stage: deploy
script:
- 'xcopy /y /s "...Publish*.*" "C:\solutionDir"'
dependencies:
- build_job
- test_job