Prev Next

DevOps / GitLab CI Basics Interview Questions

1. What is GitLab CI/CD and what problem does it solve? 2. What is the.gitlab-ci.yml file and where must it be placed? 3. What is a GitLab CI/CD pipeline? 4. What are stages in GitLab CI/CD and how do you define them? 5. What is a CI/CD job in GitLab and what are the required keywords? 6. What is a GitLab Runner and what types are available? 7. What is the 'script', 'before_script', and 'after_script' keywords and how do they differ? 8. How do you use the 'image' keyword to specify a Docker environment for a job? 9. What are GitLab CI/CD artifacts and how do you use them? 10. What is the difference between cache and artifacts in GitLab CI? 11. What are GitLab CI/CD variables and what types are available? 12. What are the most important predefined CI/CD variables in GitLab? 13. What are 'rules' in GitLab CI/CD and how do they control when jobs run? 14. What is the difference between 'only/except' and 'rules' in GitLab CI? 15. What is the 'needs' keyword in GitLab CI/CD and what problem does it solve? 16. What is the 'workflow' keyword in GitLab CI and how does it control pipeline creation? 17. What is the 'extends' keyword and how does it enable job templates? 18. What is the 'include' keyword and how do you share CI configuration across projects? 19. What are GitLab environments and how do you define them in CI/CD? 20. What are manual jobs in GitLab CI/CD and how do you configure them? 21. What is the 'allow_failure' keyword and how does it affect pipeline status? 22. How does parallel job execution work in GitLab CI/CD? 23. What are GitLab CI/CD scheduled pipelines and how do you set them up? 24. What are pipeline triggers and how can a pipeline be started without a git push? 25. What is the 'retry' keyword and how do you handle flaky tests in GitLab CI? 26. What is the 'timeout' keyword in GitLab CI and what are the defaults? 27. What is the GitLab Container Registry and how do you use it in CI/CD pipelines? 28. What are 'services' in GitLab CI/CD and how do you use them? 29. What is the 'default' keyword in GitLab CI and how does it reduce duplication? 30. What are YAML anchors and aliases in GitLab CI and how do they reduce duplication? 31. What is a merge request pipeline in GitLab CI and how does it differ from a branch pipeline? 32. What is pipeline caching and how do you configure cache keys? 33. What is the GitLab CI Lint tool and how do you validate a.gitlab-ci.yml file? 34. What are GitLab CI/CD components and how do they differ from includes? 35. What are parent-child pipelines in GitLab CI/CD? 36. What is the 'resource_group' keyword and how does it prevent concurrent deployments? 37. What are GitLab's built-in security scanning templates and how do you enable them? 38. What is the 'GIT_STRATEGY' variable in GitLab CI and what are the options? 39. What are protected branches and protected variables in GitLab CI? 40. What are common reasons a GitLab CI pipeline fails and how do you troubleshoot them?

1. What is GitLab CI/CD and what problem does it solve?

GitLab CI/CD is a built-in automation system within GitLab that automatically builds, tests, and deploys code every time a developer pushes changes to a repository. It eliminates the need for separate CI tools like Jenkins by providing pipelines as a native GitLab feature. The problems it solves:...

Read full answer

2. What is the.gitlab-ci.yml file and where must it be placed?

The .gitlab-ci.yml file is the pipeline configuration file for GitLab CI/CD. It uses YAML syntax to define stages, jobs, scripts, rules, and all other pipeline behaviour. GitLab automatically detects and runs the pipeline whenever this file is present and a triggering event occurs. Key facts: Mus...

Read full answer

3. What is a GitLab CI/CD pipeline?

A pipeline is the top-level component of GitLab CI/CD. It is a complete automated workflow that runs when triggered by an event (such as a git push). A pipeline consists of one or more stages , each containing one or more jobs . Pipeline hierarchy Level Component Description 1 (top) Pipeline The ...

Read full answer

4. What are stages in GitLab CI/CD and how do you define them?

Stages control the order of execution in a pipeline. Jobs within the same stage run in parallel; stages themselves run sequentially. If any job in a stage fails, subsequent stages are not run (unless configured otherwise). # Define stages at the top level of .gitlab-ci.yml stages: - build - test ...

Read full answer

5. What is a CI/CD job in GitLab and what are the required keywords?

A job is the fundamental unit of work in a GitLab pipeline. It defines a set of shell commands to run, where to run them, and under what conditions. Jobs run independently on runners and produce a job log accessible in the GitLab UI. # Minimum viable job (only "script" is required): hello-world: ...

Read full answer

6. What is a GitLab Runner and what types are available?

A GitLab Runner is an agent (a program) that picks up CI/CD jobs from GitLab and executes them. Runners are separate from the GitLab server - they can run on any machine including physical servers, VMs, containers, or cloud instances. Runner types by scope Type Scope Configured at Instance runner...

Read full answer

7. What is the 'script', 'before_script', and 'after_script' keywords and how do they differ?

These three keywords define the shell commands that run during a job. They execute in sequence but have different scopes and failure behaviour. Script keyword comparison Keyword When it runs Fails the job if it fails? Scope before_script Before the main script Yes Can be set globally or per-job s...

Read full answer

8. How do you use the 'image' keyword to specify a Docker environment for a job?

The image keyword specifies the Docker image that the runner uses as the execution environment for the job. This ensures each job runs in a consistent, isolated environment with all required tools pre-installed. # Set a default image for all jobs default: image: ubuntu:24.04 # Override image for ...

Read full answer

9. What are GitLab CI/CD artifacts and how do you use them?

Artifacts are files and directories that a job produces and saves after it finishes. They serve two purposes: downloading results from the GitLab UI, and passing files between jobs in subsequent stages. build-job: stage: build script: - npm ci - npm run build # creates dist/ directory artifacts: ...

Read full answer

10. What is the difference between cache and artifacts in GitLab CI?

Cache and artifacts are both mechanisms for persisting files across jobs, but they serve very different purposes and have different behaviours. Cache vs Artifacts Aspect Cache Artifacts Purpose Speed up jobs by reusing downloaded dependencies Pass build outputs between stages/jobs Storage Runner'...

Read full answer

11. What are GitLab CI/CD variables and what types are available?

CI/CD variables are key-value pairs that make values available to jobs. They are used to configure jobs without hardcoding values, store secrets safely, and pass information between pipeline components. Variable types Type Where defined Use case Predefined variables Set automatically by GitLab Pi...

Read full answer

12. What are the most important predefined CI/CD variables in GitLab?

GitLab automatically sets dozens of predefined variables for every pipeline run. These provide jobs with information about the current commit, branch, pipeline, runner, and environment without any configuration. Essential predefined variables Variable Value Common use $CI_COMMIT_SHA Full commit S...

Read full answer

13. What are 'rules' in GitLab CI/CD and how do they control when jobs run?

The rules keyword lets you add conditions that determine whether a job is included in a pipeline, skipped, or made manual. Rules are evaluated in order - the first matching rule applies and the rest are ignored. deploy-prod: stage: deploy script: - ./deploy.sh production rules: - if : $CI_COMMIT_...

Read full answer

14. What is the difference between 'only/except' and 'rules' in GitLab CI?

only and except are the original (legacy) keywords for controlling when jobs run. rules is the modern replacement introduced in GitLab 12.3 that provides more flexibility and clearer logic. only/except vs rules Aspect only/except rules Introduction GitLab initial release GitLab 12.3 Status Still ...

Read full answer

15. What is the 'needs' keyword in GitLab CI/CD and what problem does it solve?

The needs keyword creates a directed acyclic graph (DAG) of job dependencies, allowing jobs to start as soon as their specific dependencies are complete - rather than waiting for the entire previous stage to finish. This reduces total pipeline time significantly. stages: - build - test - deploy b...

Read full answer

16. What is the 'workflow' keyword in GitLab CI and how does it control pipeline creation?

The workflow keyword controls whether an entire pipeline is created at all, based on conditions. While rules on individual jobs control whether a specific job runs, workflow: rules controls whether the entire pipeline is created for a given event. # Only create pipelines for main branch, MRs, and...

Read full answer

17. What is the 'extends' keyword and how does it enable job templates?

The extends keyword lets one job inherit configuration from another job (or a hidden job used as a template). This reduces duplication and keeps the pipeline DRY (Don't Repeat Yourself). # Define a hidden job template (starts with .) . base - deploy: image: alpine:latest before_script: - apk add ...

Read full answer

18. What is the 'include' keyword and how do you share CI configuration across projects?

The include keyword lets you split pipeline configuration across multiple files or pull shared configuration from external sources. This is the foundation for sharing CI standards across many projects in an organisation. include types Type Syntax Use case local include: local: '/templates/jobs.ym...

Read full answer

19. What are GitLab environments and how do you define them in CI/CD?

Environments in GitLab CI/CD represent deployment targets - staging, production, review apps, etc. Defining an environment in a job links that deployment to the environment, enabling GitLab to track which version is deployed where and provide rollback capabilities. # Basic environment definition ...

Read full answer

20. What are manual jobs in GitLab CI/CD and how do you configure them?

A manual job is a job that is added to the pipeline but does not run automatically - it requires someone to click a button in the GitLab UI (or API call) to trigger it. Manual jobs are commonly used for production deployments that need human approval. # Method 1: using rules deploy-production: st...

Read full answer

21. What is the 'allow_failure' keyword and how does it affect pipeline status?

The allow_failure keyword controls whether a failing job causes the pipeline to fail. When set to true , the job can fail without marking the overall pipeline as failed - GitLab shows a warning icon on the job instead of a failure. # allow_failure: true - job failure does not fail the pipeline li...

Read full answer

22. How does parallel job execution work in GitLab CI/CD?

GitLab CI supports running multiple instances of the same job in parallel using the parallel keyword. This is useful for splitting test suites across multiple runners to reduce total execution time. # Run the same job N times in parallel test: stage: test image: ruby:3.2 script: - bundle exec rsp...

Read full answer

23. What are GitLab CI/CD scheduled pipelines and how do you set them up?

Scheduled pipelines run on a defined timetable (like a cron job) without requiring a code push. They are useful for nightly builds, weekly security scans, database backups, and performance benchmarks. # In .gitlab-ci.yml - detect schedule trigger: nightly-test: stage: test script: - run-full-test...

Read full answer

24. What are pipeline triggers and how can a pipeline be started without a git push?

GitLab pipelines can be triggered by multiple mechanisms beyond a git push. Understanding all trigger sources allows you to design flexible CI/CD workflows. Pipeline trigger sources ($CI_PIPELINE_SOURCE values) Source Value How triggered Git push push Developer pushes commits to any branch Merge ...

Read full answer

25. What is the 'retry' keyword and how do you handle flaky tests in GitLab CI?

The retry keyword automatically reruns a job when it fails, up to the specified number of times. This is useful for handling transient failures - network timeouts, flaky tests, or race conditions - without manual intervention. # Simple retry: retry up to 2 times on any failure flaky-test: script:...

Read full answer

26. What is the 'timeout' keyword in GitLab CI and what are the defaults?

The timeout keyword sets the maximum duration a job is allowed to run before GitLab forcefully stops it. Timeouts prevent hanging jobs from blocking runners and consuming resources indefinitely. # Job-level timeout long-running-test: script: - run-full-integration-tests.sh timeout: 2 hours # stop...

Read full answer

27. What is the GitLab Container Registry and how do you use it in CI/CD pipelines?

The GitLab Container Registry is a built-in Docker image registry integrated with every GitLab project. It provides a private place to store and manage Docker images, directly accessible from CI/CD pipelines using predefined variables. # Build and push to the GitLab Container Registry: build-imag...

Read full answer

28. What are 'services' in GitLab CI/CD and how do you use them?

Services are Docker containers that run alongside the main job container, providing supporting infrastructure like databases, message brokers, or a Docker daemon. They share a network namespace with the job container. # Run tests with a PostgreSQL database service: test-with-db: stage: test image...

Read full answer

29. What is the 'default' keyword in GitLab CI and how does it reduce duplication?

The default keyword defines configuration that applies to all jobs in the pipeline unless overridden at the job level. It acts as a global default for common settings, reducing repetition across many jobs. # Set defaults for all jobs default: image: ubuntu:24.04 before_script: - apt-get update -q...

Read full answer

30. What are YAML anchors and aliases in GitLab CI and how do they reduce duplication?

YAML anchors ( &name ) and aliases ( *name ) are standard YAML features that let you define a block once and reuse it multiple times. In GitLab CI, they reduce duplication for shared configuration like rules, before_script, or variables - without requiring the extends keyword. # Define a reusable...

Read full answer

31. What is a merge request pipeline in GitLab CI and how does it differ from a branch pipeline?

GitLab supports two types of pipelines related to merge requests: branch pipelines (triggered by a push to a branch) and merge request pipelines (triggered specifically by merge request events). Understanding the difference is essential for designing efficient review workflows. Branch pipeline vs...

Read full answer

32. What is pipeline caching and how do you configure cache keys?

Cache in GitLab CI speeds up jobs by storing files (typically dependencies like node_modules/ ) between pipeline runs. The cache key determines which jobs share a cache and when the cache is invalidated. # Basic cache with branch-scoped key: cache: key: "$CI_COMMIT_REF_SLUG" # different cache per...

Read full answer

33. What is the GitLab CI Lint tool and how do you validate a.gitlab-ci.yml file?

Before committing a .gitlab-ci.yml change and waiting for a pipeline to run, you can validate the configuration using GitLab's built-in CI Lint tool . This catches syntax errors, invalid keywords, and configuration issues immediately. # Method 1: GitLab UI # Navigate to: Build > Pipelines > then ...

Read full answer

34. What are GitLab CI/CD components and how do they differ from includes?

CI/CD components (introduced in GitLab 16.0) are a more structured, versioned, and discoverable way to share pipeline configuration across projects compared to simple include: project . They are published to the CI/CD catalog . # Using a CI/CD component in .gitlab-ci.yml: include: - component: $C...

Read full answer

35. What are parent-child pipelines in GitLab CI/CD?

Parent-child pipelines (also called dynamic pipelines) allow a job in one pipeline (the parent) to dynamically generate and trigger another pipeline (the child). This enables modular, scalable pipelines for monorepos and complex projects. # Parent pipeline (.gitlab-ci.yml): stages: - generate - t...

Read full answer

36. What is the 'resource_group' keyword and how does it prevent concurrent deployments?

The resource_group keyword ensures that only one job with the same resource group name runs at a time across all pipelines. This prevents concurrent deployments to the same environment, which can cause race conditions or configuration conflicts. # Prevent concurrent deployments to production: dep...

Read full answer

37. What are GitLab's built-in security scanning templates and how do you enable them?

GitLab provides built-in CI/CD templates for security scanning that can be included in any pipeline with a single line. These templates add jobs to your pipeline that scan for vulnerabilities without requiring manual configuration. # Include GitLab security templates: include: - template: Securit...

Read full answer

38. What is the 'GIT_STRATEGY' variable in GitLab CI and what are the options?

The GIT_STRATEGY variable controls how GitLab CI fetches your repository's code at the start of each job. Choosing the right strategy balances freshness of code against job startup speed. GIT_STRATEGY options Value Behaviour Speed Use case fetch (default) Fetches only new commits; reuses existing...

Read full answer

39. What are protected branches and protected variables in GitLab CI?

Protected branches and protected variables are security features that control who can push to critical branches and which jobs can access sensitive CI/CD variables. # Protected variables are set in: # Settings > CI/CD > Variables > Add variable # Tick "Protected variable" checkbox # A protected v...

Read full answer

40. What are common reasons a GitLab CI pipeline fails and how do you troubleshoot them?

When a pipeline fails, GitLab provides job logs, exit codes, and visual indicators to help diagnose the issue. A systematic approach to troubleshooting resolves most failures quickly. Common failure causes and fixes Failure Likely cause Fix Job stuck in 'pending' No runner available with matching...

Read full answer

«
»

Comments & Discussions