Home/Module 3

🦊 Module 3: GitLab for Network Teams

Learning Objectives: You will be able to manage GitLab projects, create Merge Requests, perform Code Reviews, and understand how CI/CD pipelines work.

⏱️ Duration: approx. 105 minutes (incl. 7 hands-on exercises)

πŸ“‹ Table of Contents

  • 1. What is GitLab?
  • 2. The GitLab Interface in Detail
  • 3. Projects and Groups
  • 4. Protected Branches
  • 5. Merge Request Workflow
  • 6. Code Review Best Practices
  • 7. Issues and Boards
  • 8. CI/CD Pipeline Fundamentals

1. What is GitLab?

GitLab is like an office building for your code: Git stores the files, but GitLab provides the infrastructure around it -- project management, access control, code reviews, and automated pipelines.

πŸ’‘GitLab vs. Git
Git = The version control tool (local on your machine)
GitLab = The platform for sharing, reviewing, and automating (in the browser)

GitLab Core Features

πŸ“ Repositories

Central storage for code and configuration files. Accessible to the entire team.

πŸ”€ Merge Requests

Propose, review, and discuss changes before they go live.

βš™οΈ CI/CD Pipelines

Automatic tests and deployments with every push.

πŸ“‹ Issues & Boards

Track tasks and bugs, plan and document work.

GitLab vs. GitHub -- A Brief Comparison

Both platforms offer similar features. Here are the key differences:

Aspect🦊 GitLabπŸ™ GitHub
Self-Hostingβœ… Free option available (CE)πŸ’° Enterprise license required
CI/CD integratedβœ… Fully built-inβœ… GitHub Actions
Merge Request / PRMerge Request (MR)Pull Request (PR)
DevOps Focusβœ… All-in-One platformMore developer-focused
Enterprise UseVery widespread (on-prem)Dominates Open Source
ℹ️Why GitLab in the Enterprise?
Many companies (incl. Cisco customers) use GitLab because it:
  • Can be installed on-premise (data privacy)
  • Offers CI/CD without external tools
  • Has LDAP/Active Directory integration
  • Supports approval workflows for compliance

2. The GitLab Interface in Detail

When you open GitLab for the first time, you will see the main navigation. Let us explore the most important areas.

GitLab Dashboard with project overview and navigation
πŸ” Enlarge
GitLab Dashboard -- Your central hub for all projects

The Left Sidebar

🦊GitLab
πŸ“ Your Project
β”œβ”€β”€ πŸ“‹ Project information
β”œβ”€β”€ πŸ“‚ Repository
β”‚ β”œβ”€β”€ Files
β”‚ β”œβ”€β”€ Commits
β”‚ β”œβ”€β”€ Branches
β”‚ └── Tags
β”œβ”€β”€ πŸ“ Issues
β”œβ”€β”€ πŸ”€ Merge requests
β”œβ”€β”€ βš™οΈ CI/CD
β”‚ β”œβ”€β”€ Pipelines
β”‚ └── Jobs
β”œβ”€β”€ πŸ“Š Analytics
└── βš™οΈ Settings

Key Areas Explained

πŸ“‚ Repository β†’ Files

Here you can see all files in your project. You can edit files directly in the browser, view the history, and switch between branches.

GitLab Repository view with file list and folder structure
πŸ” Enlarge
The Repository view shows all files and folders of your project

πŸ“‚ Repository β†’ Branches

Overview of all branches. Shows which branches are active, when the last commit was made, and whether they are protected. You can also create new branches here.

πŸ”€ Merge Requests

All open, merged, and closed Merge Requests. Filter by author, reviewer, labels, or milestone.

βš™οΈ Settings

Project settings: access rights, Protected Branches, Webhooks, CI/CD variables, Merge Request Approvals, and much more.

πŸ”§πŸ”§ Exercise 1: Explore GitLab and Create a Project (~10 Min)

Familiarize yourself with the GitLab interface.

  1. Open GitLab in the browser (URL from the instructor)
  2. Create a new project:
    • Click on New project
    • Select Create blank project
    • Name: network-config-YOURNAME
    • Visibility: Private
    • βœ… Enable "Initialize repository with a README"
  3. Explore the project:
    • Open Repository β†’ Files
    • Check out Repository β†’ Commits
    • Open Settings β†’ General
  4. Clone the project:

    Open PowerShell and navigate to your Desktop:

    cd C:\Users\admin\Desktop
    
    # Disable SSL verification (self-signed certificate)
    git config --global http.sslVerify false
    
    # Copy the HTTPS URL from GitLab (Clone button)
    git clone https://198.18.133.100/gitlab-instance-668e631e/network-config-YOURNAME.git
    cd network-config-YOURNAME
    dir
    ⚠️Self-Signed Certificate
    The lab GitLab uses a self-signed certificate. The command git config --global http.sslVerify false is necessary so that Git accepts the HTTPS connection.
βœ… Success Criterion: You have created a new project in GitLab and cloned it locally.

3. Projects and Groups

GitLab organizes repositories in a hierarchical structure. This is especially important for larger teams.

Understanding the Hierarchy

198.18.133.100 (Instance)
└── infrastructure (Group)
β”œβ”€β”€ networking (Subgroup)
β”‚ β”œβ”€β”€ datacenter-fabric (Project)
β”‚ β”œβ”€β”€ campus-switches (Project)
β”‚ └── firewall-rules (Project)
β”œβ”€β”€ compute (Subgroup)
β”‚ └── vmware-configs (Project)
└── shared-templates (Project in Group)

Why Groups?

πŸ‘₯ Shared Permissions

Permissions are granted at the group level and inherited by all projects.

πŸ“Š Overview

All projects of a team in one place. Issues and MRs can be viewed across groups.

πŸ”„ Shared Runners

CI/CD Runners can be defined at the group level and are available to all projects.

🏷️ Shared Labels

Labels, milestones, and variables can be defined at the group level.

Access Levels (Roles)

RoleCan...Typical Use
GuestView issues, commentStakeholders, Management
ReporterRead code, create issuesQA, Support
DeveloperPush, create MRs, branchesDevelopers, Network Engineers
Maintainer+ Protected Branches, merge MRsTech Leads, Senior Engineers
OwnerFull control, delete projectTeam/Department Leads

4. Protected Branches

Protected Branches are a security mechanism that prevents critical branches (such as main or production) from being accidentally or maliciously damaged.

⚠️Why is this important?
Imagine someone accidentally pushes a faulty configuration directly to main -- and the automated pipeline deploys it immediately to 500 switches. Protected Branches prevent exactly that!

What Protected Branches Prevent

🚫 Prohibited

  • β€’ Direct push to the branch
  • β€’ Force push (overwriting history)
  • β€’ Deleting the branch
  • β€’ Merging unreviewed changes

βœ… Allowed

  • β€’ Changes via Merge Requests
  • β€’ With required approvals
  • β€’ After successful pipeline
  • β€’ By authorized maintainers

Protected Branch Settings

GitLab Protected Branches settings with permission configuration
πŸ” Enlarge
Protected Branches Settings -- Here you define who can push to which branches
# Settings β†’ Repository β†’ Protected Branches
Branch:main
Allowed to merge:Maintainers
Allowed to push:No one
Require approval:1 approval required

Merge Request Approval Rules

In addition to Protected Branches, you can define Approval Rules:

  • Number of Approvals: At least X people must approve
  • Code Owners: Certain files require approval from the responsible team
  • Eligible Approvers: Only specific people/groups may approve
  • Author cannot approve: Enforce the four-eyes principle
πŸ”§πŸ”§ Exercise 2: Update README.md and Commit (~8 Min)

Update the existing README with a meaningful project description.

  1. Edit README.md:

    The file README.md already exists in the project foldernetwork-config-YOURNAME (it was created along with the project). Open it in VS Code and replace the content with the following:

    πŸ“„ README.md
    # Network Configuration
    
    This repository contains the network configuration for our VXLAN fabric.
    
    ## Structure
    
    ```
    .
    β”œβ”€β”€ inventory/        # Device inventory
    β”œβ”€β”€ host_vars/        # Device-specific variables
    β”œβ”€β”€ group_vars/       # Group variables (Spines, Leafs)
    β”œβ”€β”€ templates/        # Jinja2 templates
    └── playbooks/        # Ansible Playbooks
    ```
    
    ## Usage
    
    ```bash
    # Validate configuration
    ansible-playbook playbooks/validate.yml
    
    # Deploy configuration (staging only)
    ansible-playbook playbooks/deploy.yml -l staging
    ```
    
    ## Contact
    
    Maintainer: YOUR NAME
  2. Commit and push changes (in PowerShell):
    git status
    git add README.md
    git commit -m "docs: README mit Projektstruktur aktualisiert"
    git push origin master
  3. Alternative: Commit and push directly in VS Code

    You can also commit changes directly via the VS Code Source Control sidebar without using the terminal:

    1. Click on the Source Control icon on the left (branch symbol, or Ctrl+Shift+G)
    2. You will see the changed files under "Changes"
    3. Click on the + next to the file (or "Stage All Changes") to stage it
    4. Enter a commit message in the text field at the top
    5. Click the "Commit" button (βœ“ checkmark)
    6. Click on "Sync Changes" or the three dots β†’ Push to push to the server
    VS Code Source Control Sidebar: Stage changed files, enter commit message, click Commit button
    πŸ” Enlarge
    VS Code Source Control: Stage, commit, and push -- all without the terminal
  4. Verify in GitLab: Open your project in the browser and verify that the README is displayed.
βœ… Success Criterion: Your README.md is displayed on the project page in GitLab.
πŸ”§πŸ”§ Exercise 3: Set Up Branch Protection (~8 Min)

Protect your main branch from direct pushes.

  1. Navigate in GitLab:
    • Open your project
    • Go to Settings β†’ Repository
    • Expand Protected branches
  2. Protect the branch:
    • Branch: main
    • Allowed to merge: Maintainers
    • Allowed to push and merge: No one
    • Click Protect
  3. Test the protection (in PowerShell):
    # Try to push directly to main
    Add-Content -Path README.md -Value "# Test"
    git add .
    git commit -m "test: direkter push"
    git push origin main
    
    # Expected result: ERROR!
    # remote: GitLab: You are not allowed to push code to protected branches
  4. Undo the change:
    git reset --hard HEAD~1
  5. Disable Protected Branch again:

    So that we can push directly to main again in the following exercises, remove the branch protection:

    • Go to Settings β†’ Repository β†’ Protected branches
    • Click Unprotect next to main
    • Confirm the action
⚠️Note: Admin/Root User
Since you are logged in as the root user (administrator), the push may still go through -- admins can override Protected Branch rules. In a production environment, regular developer accounts would not have admin access and would see the error message. In that case, still revert the change with git reset --hard HEAD~1 to continue the workflow correctly.
βœ… Success Criterion: You understand how Protected Branches work. As an admin user, the push may not be blocked -- in a real environment with normal developer accounts, the error message "not allowed to push to protected branches" would appear.

5. The Merge Request Workflow in Detail

A Merge Request (MR) is like a formal change request. Instead of applying changes directly, you propose them -- and colleagues review them before they go live.

The Phases of a Merge Request

1
Draft
β†’
2
Open
β†’
3
Review
β†’
4
Approved
β†’
5
Merged

Phase 1: Draft Merge Request

A Draft MR signals: "I am still working on this, please do not review yet!" -- perfect for work-in-progress.

# Create and push feature branch
git checkout -b feature/add-vlan-100
New-Item -ItemType Directory -Force -Path vlans
Set-Content -Path vlans/vlan100.yaml -Value "vlan_id: 100`nname: Management"
git add .
git commit -m "feat: VLAN 100 fΓΌr Management hinzugefΓΌgt"
git push -u origin feature/add-vlan-100

In GitLab:

  1. Click on Create merge request
  2. Select "Mark as draft" (or prefix the title with "Draft:")
  3. Add a description of what is still missing
πŸ’‘When to use Draft?
  • When you need feedback before everything is finished
  • When the pipeline is still red
  • When you want to track the MR as a TODO for yourself
  • When you are working on a feature over several days
GitLab Merge Request creation form with title and description
πŸ” Enlarge
Creating a new Merge Request -- Title, description, and assigning a reviewer

Phase 2: Mark MR as Ready for Review

When your work is complete, remove the draft status:

  • Click on "Mark as ready"
  • Assign a Reviewer (dropdown on the right)
  • Optional: Set a Label (e.g. "needs-review")

Phase 3: Code Review

The reviewer examines your changes. In GitLab they can:

GitLab Merge Request diff view with code changes
πŸ” Enlarge
The diff view shows all changes -- green for additions, red for removals

πŸ’¬ Comments

Ask questions or suggest improvements on individual lines.

πŸ’‘ Suggestions

Propose concrete code changes that the author can apply with a single click.

🧡 Threads

Discussions on individual points. Must be "resolved" before merging.

βœ… Approve

Formal approval: "I have reviewed this, it can be merged."

Phase 4: Approval

After all comments have been addressed and threads resolved, the reviewer clicks "Approve". Depending on the configuration, multiple approvals may be required.

Phase 5: Merge

When all conditions are met (approvals, pipeline green, no open threads), the MR can be merged:

Merge Options

  • Merge -- All commits are included (default)
  • Squash and merge -- All commits are combined into one
  • Delete source branch -- Delete the feature branch after merge (recommended)
πŸ”§πŸ”§ Exercise 4: Create a Merge Request (~10 Min)

Create a complete Merge Request.

  1. Create a feature branch (in PowerShell):
    cd netzwerk-config-IHRNAME
    git checkout main
    git pull origin main
    git checkout -b feature/add-vlan-200
    
    # Create directory
    New-Item -ItemType Directory -Force -Path vlans

    Create a new file vlans/vlan200.yaml in VS Code with the following content:

    πŸ“„ vlans/vlan200.yaml
    ---
    vlan:
      id: 200
      name: Clients
      description: "Client-Netzwerk fΓΌr ArbeitsplΓ€tze"
      ip_range: "10.200.0.0/24"
      gateway: "10.200.0.1"
      dhcp_enabled: true

    Then commit and push:

    git add .
    git commit -m "feat: VLAN 200 fΓΌr Client-Netzwerk"
    git push -u origin feature/add-vlan-200
  2. Create MR in GitLab:
    • Click the link in the push output OR
    • Go to Merge requests β†’ New merge request
    • Source: feature/add-vlan-200
    • Target: main
  3. Fill in the MR:
    • Title: "feat: VLAN 200 fΓΌr Client-Netzwerk hinzufΓΌgen"
    • Description: What, why, how to test?
    • Reviewer: Leave the field empty or assign yourself (in practice, you would assign a colleague as reviewer)
⏳ Wait: Do NOT merge yet -- we will do that after the Code Review in Exercise 6.

6. Code Review Best Practices

Code Reviews are the four-eyes principle for configurations. Here are the most important rules for effective reviews.

For the Author (You create the MR)

βœ… Do

  • β€’ Small, focused MRs (max. 200-400 lines)
  • β€’ Descriptive commit messages
  • β€’ Good description: What? Why? How to test?
  • β€’ Self-review before assigning
  • β€’ Screenshots/logs for UI/output changes

❌ Don't

  • β€’ Huge MRs with 20+ files
  • β€’ Multiple independent features in one MR
  • β€’ Empty description ("fixes stuff")
  • β€’ Assigning reviewer without context

For the Reviewer (You review the MR)

βœ… Do

  • β€’ Be constructive, not critical
  • β€’ Ask questions instead of giving orders
  • β€’ Give positive feedback ("Great solution!")
  • β€’ Suggestions instead of just comments
  • β€’ Review promptly (<24h)

❌ Don't

  • β€’ Get personal
  • β€’ Just "LGTM" without real review
  • β€’ Make style issues a blocker
  • β€’ Leave it waiting for weeks

What to Check? Checklist for Network Configurations

  • ☐ Syntax correct? (YAML, Jinja2, etc.)
  • ☐ Naming conventions? (VLANs, interfaces, etc.)
  • ☐ IP addresses/ranges correct? (no overlap)
  • ☐ Security? (no secrets in code, ACLs correct)
  • ☐ Dependencies? (order, references)
  • ☐ Documentation? (comments, README up to date)
  • ☐ Tests? (pipeline green, validation successful)
GitLab Code Review with inline comments and suggestions
πŸ” Enlarge
Code Review in action -- Comments and suggestions directly on the code lines

Comment Conventions

Use prefixes to indicate importance:

PrefixMeaningExample
blocker:Must be fixedblocker: This IP is already in use!
suggestion:Improvement suggestionsuggestion: VLAN name could be more descriptive
question:Question/needs clarificationquestion: Why /24 instead of /23?
nit:Minor issue, not a blockernit: Trailing whitespace
praise:Kudos!praise: Very clean structure! πŸ‘
πŸ”§πŸ”§ Exercise 5: Perform a Code Review (~15 Min)

Practice the Code Review workflow by reviewing your own Merge Request. In practice, a colleague would perform this review -- here you learn the tools and features.

  1. Open your MR:
    • Go to Merge requests
    • Open your MR from Exercise 4
    • Switch to the Changes tab
  2. Leave comments:
    • Click on a line to leave a comment
    • Add at least 3 comments with different prefixes:
    • question: Why /24 instead of /23 for the client network?
    • nit: VLAN name could be more descriptive
    • praise: Clean YAML structure! πŸ‘
  3. Create a suggestion:
    • Create a new comment on a code line
    • Click on the Suggestion icon (πŸ’‘)
    • Write a concrete change proposal in the code block
    • E.g. change the VLAN name from "Clients" to "Client-Workstations"
  4. Respond to comments and resolve threads:
    • Reply to your own comments (e.g. "Good point, will be adjusted")
    • For the suggestion: Click Apply suggestion
    • Resolve all addressed threads via the Resolve thread button
ℹ️Why Self-Review?
In practice, a code review always follows the four-eyes principle with a colleague. Here you are practicing the GitLab features (comments, suggestions, threads) so that you can confidently use them in your day-to-day work.
βœ… Success Criterion: You have created comments with different prefixes, applied a suggestion, and resolved all threads.
πŸ”§πŸ”§ Exercise 6: Approve and Merge the Merge Request (~8 Min)

Complete the review process by approving and merging your own MR.

  1. Approve your own MR:
    • Open your MR from Exercise 4
    • Make sure all threads are resolved
    • Click on Approve
    ℹ️Self-Approval in the Workshop
    As a root/admin user, you can approve your own MR. In a production environment, this would be prevented by approval rules -- there, another colleague must approve the MR (four-eyes principle).
  2. Merge the MR:
    • Click on Merge
    • Option: Enable Delete source branch
  3. Update locally (in PowerShell):
    git checkout main
    git pull origin main
    
    # Verify that the changes are there
    dir vlans/
    Get-Content vlans/vlan200.yaml
  4. Verify in GitLab:
    • The MR shows status Merged
    • The feature branch was deleted
    • The file vlans/vlan200.yaml is visible on main
βœ… Success Criterion: The MR is merged, the feature branch is deleted, and the changes are visible locally and in GitLab on main.

7. GitLab Issues and Boards

Issues are the task management in GitLab. They track bugs, features, tasks, and everything that needs to be done.

Issue Anatomy

#42Set up VLAN 300 for Guest WiFi
Assignee:Max Mustermann
Milestone:Sprint 2024-Q1
Labels:featurepriority::high
Due date:2024-02-15

Issue Templates

Templates ensure consistent issues. Create.gitlab/issue_templates/ in your repo:

πŸ“„ .gitlab/issue_templates/Network-Change.md
## Description
<!-- What should be changed? -->

## Affected Devices/VLANs
- [ ] Switches
- [ ] Routers
- [ ] Firewalls
- [ ] VLANs:

## Planned Changes
```yaml
# Example configuration
```

## Rollback Plan
<!-- How to roll back if something goes wrong? -->

## Checklist
- [ ] Change request approved
- [ ] Tested on staging
- [ ] Maintenance window planned
- [ ] Rollback plan documented

Issue Boards

Boards are Kanban views of your issues. They help visualize the work progress.

GitLab Issue Board with Kanban columns for different work phases
πŸ” Enlarge
Issue Boards -- Visually track tasks through phases like Open, In Progress, and Done
πŸ“‹ Open
#45 Migrate DNS server
#48 Check backup route
πŸ”„ In Progress
#42 Set up VLAN 300
πŸ‘€ Review
#39 Firewall rules
βœ… Done
#38 VLAN 100 deployed
#35 NTP configured

Linking Issues with Merge Requests

Link MRs with issues to enable automatic closing:

# In the MR description or commit message:

Closes #42
Fixes #42
Resolves #42

# Multiple issues:
Closes #42, #43, #44

# Link only (without closing):
Related to #42
πŸ”§πŸ”§ Exercise 7: Create an Issue and Link it with an MR (~10 Min)

Create an issue and resolve it with a Merge Request.

  1. Create an issue:
    • Go to Issues β†’ New issue
    • Title: "Set up VLAN 300 for Guest WiFi"
    • Description:
      ## Requirement
      Guest WiFi needs its own VLAN with internet access.
      
      ## Technical Details
      - VLAN ID: 300
      - Name: Guest-WiFi
      - IP Range: 10.30.0.0/24
      - Gateway: 10.30.0.1
      
      ## Acceptance Criteria
      - [ ] VLAN configured
      - [ ] Gateway reachable
      - [ ] Internet access working
    • Add a label: feature
    • Note the issue number (e.g. #1)
  2. Feature branch with issue reference (in PowerShell):
    git checkout main
    git pull origin main
    git checkout -b feature/issue-1-vlan-300

    Create a new file vlans/vlan300.yaml in VS Code:

    πŸ“„ vlans/vlan300.yaml
    ---
    vlan:
      id: 300
      name: Guest-WiFi
      description: "GΓ€ste-WLAN mit Internet-Zugang"
      ip_range: "10.30.0.0/24"
      gateway: "10.30.0.1"
      dhcp_enabled: true
      internet_access: true
      internal_access: false

    Then commit and push:

    git add .
    git commit -m "feat: VLAN 300 fΓΌr GΓ€ste-WLAN
    
    Closes #1"
    git push -u origin feature/issue-1-vlan-300
  3. Create MR:
    • In the description: Closes #1
    • Verify that the issue is shown as linked
  4. Merge MR and check issue:
    • After the merge: Open the issue
    • It should be automatically closed!
βœ… Success Criterion: The issue was automatically closed when the MR was merged.

8. CI/CD Pipeline Fundamentals

A pipeline is like an assembly line in a factory: With every new commit, a series of steps runs automatically -- test, validate, deploy.

β„ΉοΈπŸ“Œ Note
CI/CD is covered in detail in Module 5. Here you will learn only the fundamentals to understand pipelines in GitLab.

What Does CI/CD Mean?

CI -- Continuous Integration

Tests are automatically run with every push. Errors are detected immediately, not only in production.

CD -- Continuous Delivery/Deployment

Changes are automatically deployed to staging/production. Either manually approved (Delivery) or fully automated (Deployment).

Assigning a Runner to a Project

βš οΈπŸƒ Runners must be assigned to the project!
Before a pipeline can run, your project must have access to at least one Runner. Runners are not automatically available to all projects!
  1. Navigate to Settings β†’ CI/CD β†’ Runners
  2. Under "Available specific runners" you will see the available runners
  3. Click "Enable for this project" for each runner
Two runners are available in the lab:
  • Shell Runner (Tag: shell) β€” executes jobs directly on the server
  • Docker Runner (Tag: docker) β€” executes jobs in Docker containers (for jobs with image:)

A Simple Pipeline

πŸ“„ .gitlab-ci.yml
# GitLab CI/CD Pipeline fΓΌr Netzwerk-Konfiguration
stages:
  - validate      # Stage 1: Check
  - test          # Stage 2: Test
  - deploy        # Stage 3: Deploy

# Job 1: Check YAML syntax
validate-yaml:
  stage: validate
  image: python:3.11-slim
  tags: [docker]
  before_script:
    - pip install yamllint
  script:
    - echo "πŸ” PrΓΌfe YAML-Syntax..."
    - yamllint vlans/
  rules:
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"
    - if: $CI_COMMIT_BRANCH == "main"

# Job 2: Validate configuration against schema
validate-schema:
  stage: validate
  image: python:3.11-slim
  tags: [docker]
  before_script:
    - pip install jsonschema pyyaml
  script:
    - echo "πŸ“‹ PrΓΌfe gegen Schema..."
    - python scripts/validate_schema.py
  rules:
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"

# Job 3: Deploy to staging (only for MR)
deploy-staging:
  stage: deploy
  tags: [shell]
  script:
    - echo "πŸš€ Deploye auf Staging..."
    - ansible-playbook -i staging playbooks/deploy.yml
  environment:
    name: staging
  rules:
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"
  when: manual  # Manual click required

# Job 4: Deploy to production (only main)
deploy-production:
  stage: deploy
  tags: [shell]
  script:
    - echo "πŸš€ Deploye auf Produktion..."
    - ansible-playbook -i production playbooks/deploy.yml
  environment:
    name: production
  rules:
    - if: $CI_COMMIT_BRANCH == "main"
  when: manual  # Safety: Manual click
  needs:
    - validate-yaml

Pipeline Concepts

ConceptDescription
StagesPhases of the pipeline (run sequentially)
JobsIndividual tasks (run in parallel within a stage)
RunnerThe machine/container that executes jobs
TagsLabels that determine which runner executes a job (e.g. shell, docker)
ArtifactsFiles passed between jobs
VariablesEnvironment variables (secrets, configuration)
RulesConditions for when a job runs

Pipeline Status in the MR

In the Merge Request, you can see the pipeline status:

GitLab Pipeline with green status and successful jobs
πŸ” Enlarge
A successful pipeline -- all stages green, ready to merge
πŸ”€Merge Request !15
Pipeline passed
βœ… validate-yamlβœ… validate-schema⏸️ deploy-staging (manual)
πŸ’‘Pipelines Block Merges
You can configure that MRs can only be merged when the pipeline is green. This prevents faulty configurations from landing in main.

Settings β†’ Merge requests β†’ Merge checks:
βœ… "Pipelines must succeed"

❓ Quiz: Test Your GitLab Knowledge (5 Min)

Try to answer the questions without scrolling back.

1. What is the difference between Git and GitLab?

Show Answer

Git is the version control system (command line, local).GitLab is a web platform that extends Git with features like Merge Requests, CI/CD pipelines, issue tracking, and a container registry.

2. What does a Protected Branch do?

Show Answer

A Protected Branch prevents developers from pushing directly to or deleting that branch. Changes must be submitted via Merge Requests and reviewed and merged by authorized personnel.

3. What is a Merge Request and why is it important?

Show Answer

A Merge Request is a formal change request. It shows all changes from a feature branch and enables code review by colleagues. Only after approval are the changes merged into the main branch. This is the four-eyes principle for code.

4. Describe the typical GitLab workflow in 4 steps.

Show Answer

1. Create a branch (git checkout -b feature/my-feature)
2. Commit and push changes (git push origin feature/my-feature)
3. Create a Merge Request in GitLab (with description and reviewer)
4. Review and Merge -- Colleague reviews, gives approval, MR is merged

5. What is the GitLab Container Registry and what is it used for?

Show Answer

The Container Registry is a private storage for Docker images directly in GitLab. CI/CD pipelines can store images there and retrieve them for later jobs. This keeps images close to the code and under your control.

Summary

βœ… What You Have Learned

  • β˜‘οΈ Navigate the GitLab interface
  • β˜‘οΈ Understand projects and groups
  • β˜‘οΈ Set up Protected Branches
  • β˜‘οΈ Create Merge Requests
  • β˜‘οΈ Perform Code Reviews
  • β˜‘οΈ Use Issues and Boards
  • β˜‘οΈ Link Issues with MRs
  • β˜‘οΈ Understand CI/CD Pipelines

πŸ”‘ Key Takeaways

  • Merge Requests = Controlled changes with review
  • Protected Branches = Safety net for critical branches
  • Code Reviews = Quality assurance through the four-eyes principle
  • CI/CD = Automated validation and deployment
  • Issues = Structured task management

πŸ“‹ GitLab Cheat Sheet

# Disable SSL verification (self-signed certificate)
git config --global http.sslVerify false

# Clone project
git clone https://198.18.133.100/group/project.git

# Create feature branch
git checkout -b feature/my-feature
git push -u origin feature/my-feature

# After changes
git add .
git commit -m "feat: Description of the change"
git push

# Update branch with main
git checkout main
git pull origin main
git checkout feature/my-feature
git merge main  # or: git rebase main