Blog Category: DevOps | Git | CI/CD | Cloud | Software Development
Level: Beginner to Advanced
Technology Stack: Git, GitLab, .NET Core, Docker, Kubernetes, Azure DevOps
1. Introduction to GitLab
In modern software development, managing source code, collaborating with developers, automating builds, testing applications, and deploying applications to production are essential activities.
Traditionally, development teams use multiple tools for these activities:
- Git for source code management.
- Jenkins for CI/CD automation.
- SonarQube for code quality analysis.
- Docker for containerization.
- Kubernetes for container orchestration.
- Jira for project management.
- Separate tools for security scanning and deployment.
GitLab provides an integrated DevSecOps platform that brings many of these capabilities together.
GitLab is a web-based DevOps platform built around Git. It helps development teams manage the complete software development lifecycle, from planning and coding to testing, security, deployment, and monitoring.
Official website: GitLab
Official documentation: GitLab Documentation
What can we do with GitLab?
- Create and manage Git repositories.
- Manage source code.
- Create branches and merge code.
- Perform code reviews.
- Track bugs and development tasks.
- Configure CI/CD pipelines.
- Build and test applications automatically.
- Integrate SonarQube.
- Perform security scanning.
- Build Docker images.
- Deploy applications to Azure, AWS, or Kubernetes.
- Monitor application deployments.
2. Understanding Git vs GitLab
Many developers think Git and GitLab are the same. However, they are different.
| Git | GitLab |
|---|---|
| Distributed version control system | DevOps platform |
| Tracks source code changes | Manages complete development lifecycle |
| Works locally on a computer | Provides web-based collaboration |
| Supports branches and commits | Provides merge requests |
| Supports version history | Provides repository management |
| Does not provide a built-in CI/CD platform | Provides integrated CI/CD |
| Open-source software | Offers Free, Premium, and Ultimate offerings |
Real-Time Example
Suppose we are developing an ASP.NET Core Web API.
Using Git:
A developer creates a branch, modifies the code, commits changes, and pushes them to a remote repository.
Using GitLab:
The developer pushes code to GitLab, creates a merge request, requests a code review, executes automated pipelines, checks code quality, and deploys the application.
In simple terms:
- Git manages source code versions.
- GitLab provides a platform to collaborate, automate, secure, and deliver software.
3. Understanding GitLab Architecture
Before working with GitLab, let's understand its major components.
Important GitLab Components
| Component | Description |
|---|---|
| GitLab Server | Hosts GitLab application |
| Project | Contains source code and project resources |
| Repository | Stores source code and Git history |
| Groups | Organize multiple projects |
| Branches | Maintain separate development versions |
| Commits | Record code changes |
| Merge Requests | Review and merge code |
| Issues | Track bugs and tasks |
| GitLab Runner | Executes CI/CD jobs |
| Pipeline | Automates build, test, and deployment |
| Container Registry | Stores Docker images |
| Package Registry | Stores application packages |
| Environments | Track deployments |
| Artifacts | Store pipeline outputs |
GitLab High-Level Architecture
Developers
|
|
Git Commands
|
v
+---------------+
| GitLab Server |
+---------------+
|
+-------+-------+
| |
v v
Repository Issues
|
|
Merge Request
|
v
CI/CD Pipeline
|
v
GitLab Runner
|
+-----+-------+
| |
v v
Build Testing
| |
+------+------+
|
v
Code Quality
Security Scan
|
v
Docker Image
|
v
Deployment
|
+-----+------+
| |
v v
QA ProductionThis architecture illustrates how developers can use GitLab to automate the software delivery lifecycle.
4. GitLab Account Creation and Project Setup
Let's start working practically.
Step 1: Create a GitLab Account
- Open GitLab Sign Up.
- Register an account.
- Verify your email address.
- Log in to GitLab.
GitLab offers two major deployment options.
1. GitLab.com
- Cloud-hosted GitLab platform.
- No need to maintain your own GitLab server.
- Suitable for individual developers and teams.
2. GitLab Self-Managed
- Organizations host GitLab on their own infrastructure.
- Provides administrative control.
- Organizations manage infrastructure, upgrades, and maintenance.
Step 2: Create a New Project
After logging in:
- Navigate to Projects.
- Select New Project.
- Choose Create Blank Project.
- Enter the project name.
Example:
Project Name: EmployeeManagementAPI
Description:
ASP.NET Core Web API for Employee Management.
Visibility:
Private- Initialize the repository with a README file.
- Click Create Project.
Your GitLab project is ready.
A project is the central workspace where your team manages source code, issues, merge requests, and CI/CD configurations. GitLab Docs
5. Understanding GitLab Groups and Projects
GitLab provides Groups and Projects to organize development activities.
What is a Group?
A group is a collection of related projects.
For example:
Organization
|
v
EmployeeManagement
|
+-------------------+
| |
v v
EmployeeAPI EmployeeUI
|
v
EmployeeDatabaseA group helps organizations manage:
- Multiple projects.
- Team members.
- Permissions.
- Shared CI/CD configurations.
- Project-level organization.
What is a Project?
A project represents an individual application or software product.
Example:
Group: BankingApplications
Projects:
1. CustomerAPI
2. AccountAPI
3. PaymentAPI
4. NotificationAPIEach project can maintain its own:
- Repository.
- Branches.
- Merge requests.
- Issues.
- Pipelines.
- CI/CD variables.
6. GitLab User Roles and Permissions
In enterprise projects, different team members have different responsibilities.
GitLab provides roles to control access.
| Role | Responsibility |
|---|---|
| Guest | Limited project access |
| Planner | Plan and manage work where supported |
| Reporter | View project information and issues |
| Developer | Push code and create merge requests |
| Maintainer | Manage project settings and repositories |
| Owner | Manage group or project ownership, where applicable |
Real-Time Example
Consider an enterprise .NET application development team.
| Team Member | GitLab Role |
|---|---|
| Project Manager | Planner or Reporter |
| Business Analyst | Guest or Planner |
| .NET Developer | Developer |
| Tech Lead | Maintainer |
| DevOps Engineer | Maintainer |
| Project Owner | Owner |
Best Practice: Follow the principle of least privilege. Give users only the permissions required for their responsibilities.
7. Understanding Git Branching Strategy
Branching is one of the most important concepts in GitLab.
In enterprise projects, multiple developers work on the same application simultaneously.
Instead of modifying the main branch directly, developers create separate branches.
Common Branches
| Branch | Purpose |
|---|---|
| main | Production-ready code |
| develop | Development integration |
| feature/* | New functionality |
| bugfix/* | Bug fixes |
| release/* | Release preparation |
| hotfix/* | Urgent production fixes |
Example Branch Structure
main
|
+---- develop
|
+---- feature/employee-create
|
+---- feature/employee-update
|
+---- bugfix/employee-validation
|
+---- release/1.0Real-Time Development Scenario
Suppose three developers are working on an Employee Management application.
Developer 1:
feature/employee-createDeveloper 2:
feature/employee-updateDeveloper 3:
feature/employee-deleteEach developer works independently.
After development:
- Push code to GitLab.
- Create a merge request.
- Request code review.
- Execute CI/CD pipeline.
- Get approval.
- Merge into the target branch.
This approach helps teams work independently without directly modifying production-ready code.
8. Essential Git Commands for GitLab
Git commands are important for every developer working with GitLab.
8.1 Configure Git
git config --global user.name "Developer"
git config --global user.email "developer@example.com"8.2 Clone a Repository
Cloning downloads the remote repository to your local machine.
git clone https://gitlab.com/group/project.git8.3 Navigate to Project
cd EmployeeManagementAPI8.4 Check Current Branch
git branch8.5 Create a New Branch
git checkout -b feature/employee-createAlternatively:
git switch -c feature/employee-create8.6 Check Modified Files
git status8.7 Add Files
git add .8.8 Commit Changes
git commit -m "Added employee creation API"8.9 Push Changes
git push origin feature/employee-create8.10 Pull Latest Changes
git pull origin develop8.11 Fetch Remote Changes
git fetch origin8.12 Merge Branches
git checkout develop
git merge feature/employee-create8.13 Delete a Local Branch
git branch -d feature/employee-create8.14 Delete a Remote Branch
git push origin --delete feature/employee-createGit Commands Summary
| Command | Purpose |
|---|---|
| git clone | Download repository |
| git init | Initialize repository |
| git status | Check modified files |
| git add | Stage changes |
| git commit | Save changes locally |
| git push | Upload commits |
| git pull | Fetch and integrate changes |
| git fetch | Download remote updates |
| git merge | Merge branches |
| git checkout | Switch branches |
| git branch | List branches |
| git log | View commit history |
| git stash | Temporarily save uncommitted changes |
| git reset | Move HEAD and potentially change staging |
| git revert | Create a commit that reverses another commit |
9. Understanding Merge Requests (MR)
A Merge Request is one of the most important features in GitLab.
A merge request allows developers to propose changes from one branch into another branch.
It supports:
- Code reviews.
- Discussion.
- Approval workflows.
- Pipeline validation.
- Change tracking.
- Merge conflict resolution.
Real-Time Example
Suppose a developer creates:
feature/employee-createAfter completing development, the developer pushes the branch.
git push origin feature/employee-createNow navigate to GitLab.
- Open the project.
- Navigate to Merge Requests.
- Click New Merge Request.
- Select source branch.
- Select target branch.
- Add a title and description.
- Assign reviewers.
- Create the merge request.
Example:
Source Branch:
feature/employee-create
Target Branch:
develop
Title:
Implemented Employee Creation APIMerge Request Workflow
Developer
|
v
Create Feature Branch
|
v
Write Code
|
v
Commit Changes
|
v
Push to GitLab
|
v
Create Merge Request
|
v
Code Review
|
v
Pipeline Validation
|
v
Approval
|
v
Merge into DevelopWhat happens during code review?
The reviewer checks:
- Coding standards.
- Business logic.
- SQL query performance.
- Exception handling.
- Security vulnerabilities.
- Duplicate code.
- Unit test coverage.
- Code complexity.
Important: GitLab can enforce approval requirements and pipeline success before allowing a merge, depending on project configuration. GitLab Docs
10. Understanding GitLab Issues
GitLab Issues help development teams track tasks, bugs, enhancements, and technical activities.
Example
Suppose the Employee API is returning HTTP 500 when creating an employee.
Create an issue:
Issue Title:
Employee API Returning 500 Error
Description:
Employee creation API is failing
when submitting valid employee details.
Priority:
High
Assigned To:
Developer
Labels:
Bug, API, BackendCommon Issue Types
- Bug.
- Feature.
- Enhancement.
- Technical Debt.
- Production Issue.
- Performance Improvement.
Issue Lifecycle
New Issue
|
v
Assigned
|
v
In Progress
|
v
Code Fix
|
v
Code Review
|
v
Testing
|
v
ClosedIssues can also be linked to merge requests so that development activities remain traceable.
11. GitLab CI/CD – Complete Explanation
This is one of the most important sections.
GitLab CI/CD automates the application development and deployment process.
CI/CD stands for:
- CI – Continuous Integration.
- CD – Continuous Delivery or Continuous Deployment.
What is Continuous Integration?
Continuous Integration means developers frequently integrate their code changes into a shared repository.
Whenever code is pushed, automated processes can:
- Restore dependencies.
- Compile the application.
- Execute unit tests.
- Perform code quality checks.
- Generate build artifacts.
What is Continuous Delivery?
Continuous Delivery ensures that successfully validated application builds are ready for deployment.
A production deployment may require manual approval.
What is Continuous Deployment?
Continuous Deployment automatically deploys successfully validated changes to production when the configured conditions are satisfied.
GitLab CI/CD Architecture
Developer Pushes Code
|
v
GitLab Repository
|
v
CI/CD Pipeline
|
v
GitLab Runner
|
v
Build Job
|
v
Test Job
|
v
SonarQube Analysis
|
v
Security Scanning
|
v
Docker Build
|
v
Container Registry
|
v
Deployment
|
v
ProductionGitLab CI/CD uses a configuration file called .gitlab-ci.yml. It defines pipeline stages, jobs, scripts, variables, and dependencies. GitLab Docs
12. Understanding GitLab CI/CD Components
Before creating a pipeline, understand these important components.
12.1 Pipeline
A pipeline is a collection of jobs that execute according to defined rules and dependencies.
Example:
Pipeline
|
+---- Build
|
+---- Test
|
+---- Code Quality
|
+---- Deploy12.2 Stages
Stages define the execution sequence.
Example:
stages:
- build
- test
- quality
- deployStages normally execute sequentially.
12.3 Jobs
Jobs define the actual activities.
Example:
build-job:
stage: build
script:
- echo "Building application"12.4 Runner
A GitLab Runner is an application that executes CI/CD jobs.
Think of the runner as a worker that receives pipeline jobs and executes the configured commands.
For example:
GitLab Server
|
v
Pipeline Created
|
v
Job Assigned
|
v
GitLab Runner
|
v
Execute Commands
|
v
Return Job Status12.5 Artifacts
Artifacts are files generated by pipeline jobs.
Examples:
- DLL files.
- ZIP packages.
- Test reports.
- Code coverage reports.
- Build outputs.
12.6 Cache
Cache stores reusable files between pipeline jobs or executions to reduce build time.
Example:
cache:
paths:
- .nuget/packages/Artifacts and cache serve different purposes: artifacts pass job outputs, while caches improve execution efficiency.
13. Create Your First GitLab CI/CD Pipeline
Let's create a simple pipeline.
Step 1: Open Your GitLab Project
Navigate to:
Project
|
v
Code
|
v
RepositoryStep 2: Create a New File
Create:
.gitlab-ci.ymlThis file must be placed in the root directory of your repository unless you configure a custom pipeline file.
Step 3: Add the Following YAML
stages:
- build
- test
- deploy
build-job:
stage: build
script:
- echo "Building application"
test-job:
stage: test
script:
- echo "Running unit tests"
deploy-job:
stage: deploy
script:
- echo "Deploying application"Step 4: Commit the File
Commit the changes to your repository.
GitLab automatically detects the pipeline configuration and can trigger a pipeline based on the configured events.
Step 5: Check Pipeline Execution
Navigate to:
Build
|
v
PipelinesYou should see:
Pipeline Status
Build SUCCESS
Test SUCCESS
Deploy SUCCESSThis is your first GitLab CI/CD pipeline.
14. Real-Time GitLab CI/CD Pipeline for .NET 8 Web API
Now let's implement a practical example using an ASP.NET Core Web API.
Project Structure
EmployeeManagementAPI
|
+---- Controllers
|
+---- Models
|
+---- Services
|
+---- Data
|
+---- EmployeeManagementAPI.csproj
|
+---- EmployeeManagementAPI.sln
|
+---- .gitlab-ci.ymlPipeline Requirements
We need to automate:
- Restore NuGet packages.
- Build the application.
- Execute unit tests.
- Publish application files.
- Deploy to a development environment.
Complete .gitlab-ci.yml
stages:
- restore
- build
- test
- publish
variables:
DOTNET_CLI_TELEMETRY_OPTOUT: "1"
DOTNET_NOLOGO: "true"
BUILD_CONFIGURATION: "Release"
default:
image: mcr.microsoft.com/dotnet/sdk:8.0
restore-job:
stage: restore
script:
- dotnet restore EmployeeManagementAPI.sln
build-job:
stage: build
script:
- dotnet build EmployeeManagementAPI.sln
--configuration $BUILD_CONFIGURATION
--no-restore
test-job:
stage: test
script:
- dotnet test EmployeeManagementAPI.sln
--configuration $BUILD_CONFIGURATION
--no-build
publish-job:
stage: publish
script:
- dotnet publish EmployeeManagementAPI/EmployeeManagementAPI.csproj
--configuration $BUILD_CONFIGURATION
--output publish
artifacts:
paths:
- publish/
expire_in: 1 weekNote: Replace the solution and project paths with your actual repository paths. This example assumes the application targets .NET 8 and has a compatible test project.
Explanation
Restore Stage
dotnet restoreDownloads the required NuGet packages.
Build Stage
dotnet buildCompiles the application and identifies compilation errors.
Test Stage
dotnet testExecutes automated unit tests.
Publish Stage
dotnet publishGenerates application deployment files.
Expected Pipeline Execution
Restore
|
v
Build
|
v
Test
|
v
Publish
|
v
Artifacts Generated15. Integrating SonarQube with GitLab
SonarQube is widely used in enterprise projects to identify code quality issues.
It helps developers identify:
- Bugs.
- Code smells.
- Security vulnerabilities.
- Duplicated code.
- Maintainability issues.
- Code complexity.
- Test coverage information.
GitLab + SonarQube Architecture
Developer
|
v
Push Code to GitLab
|
v
GitLab Pipeline
|
v
Build Application
|
v
SonarQube Scanner
|
v
Analyze Source Code
|
v
SonarQube Server
|
v
Quality Gate
|
+----------+
| |
v v
Passed Failed
| |
v v
Continue Fix Issues
Pipeline |
v
RecheckStep 1: Configure SonarQube
You need:
- SonarQube server.
- SonarQube project.
- Project key.
- Authentication token.
- Scanner compatible with your build environment.
Step 2: Configure GitLab Variables
Navigate to:
Project
|
v
Settings
|
v
CI/CD
|
v
VariablesAdd:
SONAR_HOST_URL
SONAR_TOKEN
SONAR_PROJECT_KEYProtect and mask sensitive variables as appropriate.
Step 3: Configure Pipeline
For a .NET project, an illustrative scanner sequence is:
sonarqube-analysis:
stage: quality
script:
- dotnet tool install --global dotnet-sonarscanner
- export PATH="$PATH:$HOME/.dotnet/tools"
- dotnet sonarscanner begin
/k:"$SONAR_PROJECT_KEY"
/d:sonar.host.url="$SONAR_HOST_URL"
/d:sonar.token="$SONAR_TOKEN"
- dotnet build EmployeeManagementAPI.sln
- dotnet sonarscanner end
/d:sonar.token="$SONAR_TOKEN"Important: In a real pipeline, SonarScanner's begin step must execute before the build, and its end step must execute after the build. Configure the appropriate scanner version and analysis settings for your SonarQube edition.
How to Fix SonarQube Issues?
Suppose SonarQube identifies:
Issue:
Method has high cognitive complexity.
File:
EmployeeService.cs
Severity:
MajorDeveloper activities:
- Open the SonarQube dashboard.
- Navigate to the identified issue.
- Understand the code quality rule.
- Refactor the method.
- Commit the changes.
- Push the updated code.
- Execute the pipeline again.
- Verify the new SonarQube analysis.
This helps maintain code quality throughout development.
16. GitLab CI/CD Variables and Secrets Management
In enterprise applications, pipelines require different configuration values.
Examples:
Database Connection String
API URL
Azure Client ID
Azure Client Secret
Docker Registry Credentials
SonarQube TokenNever store sensitive information directly inside .gitlab-ci.yml.
Configure Variables
Navigate to:
Project
|
v
Settings
|
v
CI/CD
|
v
VariablesCreate:
| Variable | Example |
|---|---|
| DATABASE_URL | Database endpoint |
| API_URL | API endpoint |
| SONAR_TOKEN | SonarQube token |
| AZURE_CLIENT_ID | Azure application ID |
| AZURE_CLIENT_SECRET | Secret value |
Example YAML:
deploy-job:
stage: deploy
script:
- echo "Deploying application"
- echo "$API_URL"For production applications, avoid printing secrets in pipeline logs.
Important Variable Types
Masked Variables: Help prevent variable values from appearing in logs.
Protected Variables: Restrict access to pipelines running on protected branches or tags.
Environment-scoped Variables: Allow different values for development, QA, and production environments.
GitLab supports project, group, and instance-level CI/CD variables. GitLab Docs
17. GitLab Docker Integration
Docker is widely used in modern application deployments.
GitLab supports container image building and provides a Container Registry to store images.
Architecture
.NET Application
|
v
Dockerfile
|
v
Docker Build
|
v
Docker Image
|
v
GitLab Container Registry
|
v
Kubernetes / Azure
|
v
Running ApplicationExample Dockerfile for .NET 8
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime
WORKDIR /app
EXPOSE 8080
COPY publish/ .
ENTRYPOINT ["dotnet", "EmployeeManagementAPI.dll"]This example expects the publish directory to be available in the Docker build context.
Docker Build Command
docker build -t employee-api:1.0 .Run Container
docker run -d -p 8080:8080 employee-api:1.0GitLab Container Registry
Navigate to:
Project
|
v
Deploy
|
v
Container RegistryThe registry stores Docker images generated through CI/CD pipelines.
18. GitLab CI/CD Pipeline for Docker Build
Example:
stages:
- build
- docker
build-job:
stage: build
image: mcr.microsoft.com/dotnet/sdk:8.0
script:
- dotnet restore
- dotnet publish -c Release -o publish
artifacts:
paths:
- publish/
docker-build:
stage: docker
image: docker:cli
services:
- name: docker:dind
alias: docker
variables:
DOCKER_HOST: tcp://docker:2376
DOCKER_TLS_CERTDIR: "/certs"
script:
- echo "$CI_REGISTRY_PASSWORD" |
docker login "$CI_REGISTRY"
-u "$CI_REGISTRY_USER" --password-stdin
- docker build -t "$CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA" .
- docker push "$CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA"Note: This is an illustrative Docker-in-Docker configuration. Your runner must support the required service and networking configuration. For production, consider rootless BuildKit or another approved image-building approach to reduce privileged runner requirements.
19. GitLab Deployment to Azure Kubernetes Service (AKS)
Let's understand how GitLab can deploy a containerized .NET application to Azure Kubernetes Service.
Architecture
Developer
|
v
GitLab Repository
|
v
GitLab Pipeline
|
v
.NET Build
|
v
Unit Testing
|
v
SonarQube
|
v
Docker Build
|
v
GitLab Container Registry
|
v
Azure Container Registry
|
v
Azure Kubernetes Service
|
v
Application RunningDeployment Steps
- Create an AKS cluster.
- Configure Azure Container Registry.
- Build the Docker image.
- Push the image to the registry.
- Configure secure Azure authentication for GitLab.
- Connect the deployment job to AKS.
- Apply Kubernetes deployment manifests.
- Verify application health.
Kubernetes Deployment YAML
Create:
deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: employee-api
spec:
replicas: 2
selector:
matchLabels:
app: employee-api
template:
metadata:
labels:
app: employee-api
spec:
containers:
- name: employee-api
image: myregistry.azurecr.io/employee-api:latest
ports:
- containerPort: 8080Kubernetes Service YAML
Create:
service.yaml
apiVersion: v1
kind: Service
metadata:
name: employee-api-service
spec:
type: ClusterIP
selector:
app: employee-api
ports:
- port: 80
targetPort: 8080Deploy to AKS
Once authentication and Kubernetes context are configured:
kubectl apply -f deployment.yaml
kubectl apply -f service.yamlCheck deployment:
kubectl get deploymentsCheck pods:
kubectl get podsCheck services:
kubectl get servicesFor production, use immutable image tags rather than relying on latest, and configure appropriate resource requests, limits, health probes, and deployment permissions.
20. GitLab Environments – Development, QA, UAT, Production
Enterprise applications typically have multiple deployment environments.
| Environment | Purpose |
|---|---|
| Development | Developer testing |
| QA | Functional testing |
| SIT | System integration testing |
| UAT | Business acceptance testing |
| Staging | Production-like validation |
| Production | Live application |
Environment Deployment Flow
GitLab Pipeline
|
v
Development
|
v
QA
|
v
SIT
|
v
UAT
|
v
ProductionExample GitLab Deployment Job
deploy-development:
stage: deploy
script:
- echo "Deploying to Development"
environment:
name: development
rules:
- if: '$CI_COMMIT_BRANCH == "develop"'Production deployment should be protected and should require appropriate authorization.
GitLab environments help track deployments, while protected environments and deployment approvals can restrict production access. GitLab Docs
21. GitLab Security and DevSecOps
Security is an important part of enterprise application development.
GitLab provides security capabilities that can be integrated into CI/CD workflows.
Important Security Scanning Types
| Security Scan | Purpose |
|---|---|
| SAST | Identify source code security issues |
| DAST | Test running applications for vulnerabilities |
| Dependency Scanning | Identify vulnerable dependencies |
| Secret Detection | Detect exposed secrets |
| Container Scanning | Identify container image vulnerabilities |
| IaC Scanning | Identify infrastructure configuration issues |
DevSecOps Workflow
Plan
|
v
Code
|
v
Build
|
v
Test
|
v
Security Scanning
|
v
Package
|
v
Deploy
|
v
MonitorExample Security Configuration
GitLab provides security templates that can be included in CI/CD configuration.
For example:
include:
- template: Jobs/SAST.gitlab-ci.ymlThe exact available templates and features depend on your GitLab version and subscription tier.
Security findings should be reviewed and addressed according to your organization's security policies.
22. GitLab Pipeline Troubleshooting
As a developer or DevOps engineer, troubleshooting pipeline failures is an essential responsibility.
Let's understand common issues.
Issue 1: Pipeline Failed
Possible reasons:
- Compilation errors.
- Missing dependencies.
- Incorrect YAML configuration.
- Runner unavailable.
- Environment configuration problems.
How to troubleshoot:
- Open the GitLab project.
- Navigate to Build → Pipelines.
- Open the failed pipeline.
- Select the failed job.
- Review the job logs.
- Identify the failing command.
- Fix the issue and rerun the pipeline.
Issue 2: GitLab Runner Not Available
Error:
This job is stuck because there are no runners available.Possible reasons:
- No runner registered.
- Runner is offline.
- Runner tags do not match.
- Runner is not allowed to execute the job.
Solution:
Check:
Project
|
v
Settings
|
v
CI/CD
|
v
RunnersIssue 3: Docker Build Failed
Possible reasons:
- Dockerfile missing.
- Invalid Docker syntax.
- Registry authentication failure.
- Docker daemon unavailable.
- Insufficient disk space.
Check Docker build logs and runner configuration.
Issue 4: Deployment Failed
Possible reasons:
- Invalid Kubernetes credentials.
- Incorrect cluster endpoint.
- Image unavailable.
- Insufficient deployment permissions.
- Invalid Kubernetes YAML.
Useful commands:
kubectl get pods
kubectl describe pod employee-api
kubectl get events
kubectl logs deployment/employee-apiIssue 5: Merge Request Pipeline Failed
Possible reasons:
- Unit tests failed.
- Code quality checks failed.
- Security scanning identified blocking issues.
- Build errors.
Review the failed job before merging.
23. GitLab Integration with Other Tools
GitLab can integrate with several tools used in enterprise software development.
| Tool | Integration Purpose |
|---|---|
| SonarQube | Code quality analysis |
| Docker | Containerization |
| Kubernetes | Container orchestration |
| Azure | Cloud infrastructure |
| AWS | Cloud infrastructure |
| Jira | Project management |
| Slack | Team notifications |
| Terraform | Infrastructure as Code |
| NuGet | Package management |
| Prometheus | Metrics monitoring |
| Grafana | Monitoring dashboards |
These integrations help organizations establish automated development and deployment workflows.
24. GitLab Best Practices for Enterprise Projects
Following best practices improves maintainability, security, and deployment reliability.
Source Code Management
- Follow a consistent branching strategy.
- Never push directly to protected production branches unless explicitly permitted.
- Use meaningful commit messages.
- Keep feature branches small.
- Remove merged branches when appropriate.
Merge Requests
- Require code reviews.
- Link merge requests to relevant issues.
- Require successful pipelines.
- Follow approval policies.
- Review code quality and security findings.
CI/CD
- Keep pipeline configuration maintainable.
- Use reusable templates.
- Avoid unnecessary pipeline executions.
- Store important build outputs as artifacts.
- Use caching appropriately.
- Separate build and deployment responsibilities.
Security
- Never hardcode passwords.
- Use protected and masked variables.
- Restrict production deployment permissions.
- Scan dependencies.
- Scan container images.
- Rotate credentials according to organizational policy.
Production Deployment
- Use immutable image tags.
- Maintain deployment history.
- Validate application health.
- Implement rollback procedures.
- Monitor application logs and metrics.
25. Real-Time Enterprise Project Example
Let's combine everything into one practical scenario.
Suppose an organization is developing an Employee Management System using:
Backend: ASP.NET Core Web API
Frontend: Angular
Database: Azure SQL Database
Repository: GitLab
Code Quality: SonarQube
Containerization: Docker
Orchestration: Azure Kubernetes Service
Cloud: Microsoft Azure
Complete Development Workflow
Step 1: Project Creation
The DevOps engineer creates a GitLab group:
EmployeeManagementProjects:
EmployeeAPI
EmployeeUI
EmployeeDatabaseStep 2: Developer Creates a Branch
git checkout -b feature/employee-createStep 3: Developer Implements API
Example:
[ApiController]
[Route("api/[controller]")]
public class EmployeeController : ControllerBase
{
[HttpPost]
public IActionResult CreateEmployee(Employee employee)
{
if (employee == null)
{
return BadRequest();
}
return Ok("Employee created successfully");
}
}Step 4: Commit and Push Code
git add .
git commit -m "Implemented employee creation API"
git push origin feature/employee-createStep 5: Create Merge Request
The developer creates a merge request targeting the develop branch.
Step 6: Automated Pipeline
GitLab executes:
Restore
|
v
Build
|
v
Unit Testing
|
v
SonarQube
|
v
Security Scan
|
v
Docker BuildStep 7: Code Review
The team lead reviews the code and approves the merge request according to project policies.
Step 8: Merge Code
The feature branch is merged into develop.
Step 9: Deployment
The application is deployed to the development environment.
Step 10: QA Validation
The QA team performs functional and integration testing.
Step 11: Production Deployment
After the required approvals, the application is deployed to AKS.
Step 12: Monitoring
The team monitors:
- Application availability.
- API response time.
- HTTP errors.
- Container health.
- CPU and memory consumption.
- Application logs.
This is a practical example of using GitLab throughout an enterprise software delivery lifecycle.
26. GitLab vs GitHub vs Azure DevOps
These three platforms are commonly used in enterprise organizations.
| Feature | GitLab | GitHub | Azure DevOps |
|---|---|---|---|
| Git Repository | Yes | Yes | Yes |
| Branch Management | Yes | Yes | Yes |
| Merge Requests / Pull Requests | Merge Requests | Pull Requests | Pull Requests |
| CI/CD | GitLab CI/CD | GitHub Actions | Azure Pipelines |
| Code Review | Yes | Yes | Yes |
| Issue Tracking | Yes | Yes | Yes |
| Container Registry | Yes | GitHub Container Registry | Azure Container Registry integration |
| Security Scanning | Yes | Yes | Available through integrations and security services |
| Kubernetes Integration | Yes | Yes | Yes |
| Cloud Integration | Multiple clouds | Multiple clouds | Strong Azure integration |
Which One Should We Choose?
GitLab:
Suitable for organizations looking for an integrated DevSecOps platform with source code management and CI/CD.
GitHub:
Suitable for organizations that prioritize Git-based collaboration, open-source development, and GitHub Actions.
Azure DevOps:
Suitable for organizations using Azure Boards, Azure Repos, Azure Pipelines, and Microsoft development ecosystems.
The right choice depends on organizational requirements, existing infrastructure, security policies, and licensing.
27. Important GitLab Interview Questions and Answers
Here are some commonly asked GitLab interview questions.
1. What is GitLab?
GitLab is a DevOps platform that provides source code management, collaboration, CI/CD automation, security scanning, and deployment capabilities.
2. What is the difference between Git and GitLab?
Git is a distributed version control system, whereas GitLab is a platform built around Git that provides repository hosting and DevOps capabilities.
3. What is a GitLab Runner?
A GitLab Runner is an application that executes CI/CD jobs defined in a GitLab pipeline.
4. What is .gitlab-ci.yml?
It is a YAML configuration file that defines pipeline stages, jobs, scripts, variables, and execution rules.
5. What is a GitLab pipeline?
A pipeline is a collection of automated jobs that build, test, validate, and deploy an application.
6. What is a GitLab Merge Request?
A merge request allows developers to propose changes from one branch into another branch after code review and validation.
7. What is the difference between a pipeline and a job?
A pipeline contains multiple jobs. A job represents an individual task such as building, testing, or deploying an application.
8. What is a GitLab artifact?
An artifact is a file or collection of files generated by a pipeline job and stored for later use or download.
9. What is the difference between cache and artifacts?
Cache improves pipeline performance by reusing files, whereas artifacts preserve job outputs for later stages or downloads.
10. How do you configure environment-specific variables?
Use GitLab CI/CD variables with appropriate environment scopes.
11. How do you restrict production deployment?
Configure protected branches, protected environments, deployment approvals, and appropriate permissions.
12. What happens when a pipeline fails?
The failed job is marked as failed, and dependent jobs generally do not execute unless configured otherwise.
13. How do you integrate SonarQube with GitLab?
Configure the SonarQube server, project credentials, and scanner in the GitLab CI/CD pipeline.
14. What is GitLab Container Registry?
It is a registry used to store and manage Docker and OCI container images.
15. What is the difference between GitLab.com and GitLab Self-Managed?
GitLab.com is hosted and maintained by GitLab, whereas Self-Managed allows organizations to host and administer their own GitLab instance.
28. Important GitLab Commands Cheat Sheet
| Command | Description |
|---|---|
git clone <url> | Clone repository |
git init | Initialize repository |
git status | Check repository status |
git add . | Stage changes |
git commit -m "message" | Commit changes |
git push origin branch | Push branch |
git pull origin branch | Pull branch changes |
git fetch origin | Fetch remote changes |
git branch | List branches |
git checkout -b branch | Create branch |
git switch branch | Switch branch |
git merge branch | Merge branch |
git log | View commit history |
git stash | Temporarily save changes |
git cherry-pick <commit> | Apply a specific commit |
git revert <commit> | Reverse a commit |
git remote -v | View remote repositories |
29. Advantages and Disadvantages of GitLab
Advantages
- Integrated DevOps platform.
- Built-in CI/CD capabilities.
- Source code version control.
- Automated application builds.
- Merge request-based code reviews.
- Security scanning capabilities.
- Docker and Kubernetes integrations.
- Project management features.
- Supports cloud and self-managed deployments.
- Automation across the software development lifecycle.
Disadvantages
- Advanced features may require paid subscriptions.
- Self-managed installations require infrastructure maintenance.
- Complex pipelines require YAML knowledge.
- Runner configuration can require DevOps expertise.
- Large pipelines can consume significant computing resources.
- Enterprise implementations require proper security and permission management.
30. Conclusion
GitLab is more than a source code repository management platform. It provides an integrated environment for managing the complete software development lifecycle.
From creating repositories and managing branches to implementing merge requests, automating builds, integrating SonarQube, building Docker images, and deploying applications to Kubernetes, GitLab helps organizations streamline their DevOps processes.
For .NET developers, understanding GitLab CI/CD is particularly valuable because it enables automation of application restoration, compilation, unit testing, code quality validation, packaging, and deployment.
For DevOps engineers, GitLab provides capabilities to implement automated deployment workflows, manage infrastructure integrations, and establish DevSecOps practices.
The most important takeaway is that GitLab helps connect development, testing, security, and operations into one continuous software delivery workflow.
Official GitLab Learning Resources
For additional learning, refer to these official resources:
- GitLab Documentation
- GitLab CI/CD Documentation
- GitLab First Pipeline Tutorial
- GitLab Project Management
- GitLab Deployment Documentation
Suggested Blog SEO Details
| SEO Element | Content |
|---|---|
| SEO Title | Complete Guide to GitLab: From Beginner to Advanced |
| Focus Keyword | GitLab Tutorial |
| Secondary Keywords | GitLab CI/CD, GitLab Pipeline, GitLab Runner, GitLab DevOps |
| Category | DevOps |
| Suggested URL Slug | complete-guide-to-gitlab |
| Meta Description | Learn GitLab from scratch with this end-to-end guide covering Git repositories, branching, merge requests, CI/CD pipelines, SonarQube, Docker, Kubernetes, and Azure deployment. |
| Tags | GitLab, Git, DevOps, CI/CD, Docker, Kubernetes, SonarQube, Azure |
Suggested next article: Complete Guide to GitLab CI/CD Pipeline for ASP.NET Core Applications with SonarQube, Docker, and AKS – Real-Time Enterprise Implementation.

No comments:
Post a Comment