DevOps / GitLab CI Basics Interview Questions
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...
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....
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)....
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....
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....
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....
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....
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....
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....
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...
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....
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.
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....
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....
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...
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....
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)....
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....
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....
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...
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...
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....
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....
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....
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....
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....
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....
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....
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....
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...
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....
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....
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....
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 ....
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....
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....
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....
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....
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 #...
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....