{"id":5743,"date":"2026-11-19T04:46:41","date_gmt":"2026-11-19T04:46:41","guid":{"rendered":"https:\/\/www.devopssupport.in\/blog\/?p=5743"},"modified":"2026-11-19T04:46:43","modified_gmt":"2026-11-19T04:46:43","slug":"gitlab-ci-cd-getting-started-guide-build-your-first-automated-pipeline","status":"publish","type":"post","link":"https:\/\/www.devopssupport.in\/blog\/gitlab-ci-cd-getting-started-guide-build-your-first-automated-pipeline\/","title":{"rendered":"GitLab CI\/CD Getting Started Guide: Build Your First Automated Pipeline"},"content":{"rendered":"\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"572\" src=\"https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2026\/11\/image-26.png\" alt=\"\" class=\"wp-image-5744\" srcset=\"https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2026\/11\/image-26.png 1024w, https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2026\/11\/image-26-300x168.png 300w, https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2026\/11\/image-26-768x429.png 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">1. Introduction: Your First Step Into GitLab CI\/CD<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Software development becomes significantly slower and more error-prone when teams rely on manual steps to build, test, and release code. Every time a developer copies files to a server by hand, forgets to run a test suite before merging changes, or struggles with environment mismatches between their laptop and a staging server, valuable engineering time is lost. Continuous Integration and Continuous Delivery (CI\/CD) solve these challenges by automating the path from code commit to working software.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">GitLab CI\/CD is a built-in automation engine integrated directly into the GitLab platform. Rather than stitching together separate version control tools, external build servers, and third-party deployment scripts, GitLab allows you to define your entire software delivery workflow inside your repository. Whether you are exploring DevOps practices independently or building foundational automation skills through structured learning resources like DevOpsSchool, mastering GitLab CI\/CD is one of the most practical ways to understand modern software engineering.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this <strong>GitLab CI\/CD Getting Started Guide<\/strong>, you will move from basic concepts to a complete, working automation workflow. By following the steps in this tutorial, you will prepare a sample Node.js web application, verify runner availability, write your first <code>.gitlab-ci.yml<\/code> configuration file, automate unit tests, save build outputs, manage environment variables, and simulate a deployment to a staging environment.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2. Get Familiar With the GitLab Environment<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Before writing configuration files, it helps to understand where CI\/CD lives inside the GitLab user interface. GitLab organizes software projects around repositories and surrounds them with collaboration, security, and automation tools.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Key Areas of a GitLab Project<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>GitLab Projects and Repositories:<\/strong> A project is the top-level container for your work. Inside it sits your Git repository, which stores your application source code, documentation, and CI\/CD configuration files.<\/li>\n\n\n\n<li><strong>Branches and Commits:<\/strong> Branches isolate lines of development, such as a <code>main<\/code> branch for stable code and feature branches for new work. Every commit pushed to a branch acts as a potential trigger for automated checks.<\/li>\n\n\n\n<li><strong>Merge Requests (MRs):<\/strong> When a developer finishes work on a feature branch, they open a merge request to propose merging those changes into <code>main<\/code>. GitLab displays pipeline test results directly inside the merge request so reviewers know whether the new code breaks existing functionality.<\/li>\n\n\n\n<li><strong>Pipeline Interface:<\/strong> Located under <strong>Build &gt; Pipelines<\/strong> in the left sidebar, this dashboard lists every automated workflow run, who triggered it, which branch it ran on, and whether it passed or failed.<\/li>\n\n\n\n<li><strong>CI\/CD Configuration:<\/strong> Under <strong>Build &gt; Pipeline editor<\/strong>, GitLab provides a browser-based YAML editor with built-in syntax validation and visual pipeline previews.<\/li>\n\n\n\n<li><strong>Project Settings:<\/strong> Located under <strong>Settings &gt; CI\/CD<\/strong>, this section lets you configure runners, manage secret variables, set artifact retention rules, and control pipeline permissions.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">GitLab CI\/CD vs. GitLab Runner<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A common point of confusion for beginners is the difference between <strong>GitLab CI\/CD<\/strong> and <strong>GitLab Runner<\/strong>. Although they work together tightly, they perform distinct roles:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><td><strong>Component<\/strong><\/td><td><strong>Primary Role<\/strong><\/td><td><strong>Where It Lives<\/strong><\/td><\/tr><\/thead><tbody><tr><td><strong>GitLab CI\/CD<\/strong><\/td><td>The coordinator and brain. It reads your <code>.gitlab-ci.yml<\/code> file, decides which jobs need to run, schedules them in order, and displays logs and statuses in the web interface.<\/td><td>Inside the GitLab server\/platform itself.<\/td><\/tr><tr><td><strong>GitLab Runner<\/strong><\/td><td>The worker agent. It polls GitLab for queued jobs, checks out your code, executes the shell commands defined in your jobs, and reports the results back to GitLab.<\/td><td>On separate compute machines (cloud VMs, containers, or dedicated servers) managed by GitLab or your team.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Think of GitLab CI\/CD as the project manager assigning tasks and GitLab Runner as the technician executing those tasks on a workstation. Without an active runner, GitLab CI\/CD can schedule a pipeline, but no jobs will ever execute.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">3. Understand the Building Blocks Before Starting<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">GitLab CI\/CD uses a clear hierarchy of concepts to organize automation. Understanding these eight terms will make reading and writing pipeline configurations straightforward.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Pipeline:<\/strong> The top-level automated workflow triggered by an event, such as pushing a commit or opening a merge request.<\/li>\n\n\n\n<li><strong>Stages:<\/strong> Logical phases within a pipeline that execute sequentially. Common stages include <code>build<\/code>, <code>test<\/code>, and <code>deploy<\/code>. All jobs in one stage must succeed before the next stage begins.<\/li>\n\n\n\n<li><strong>Jobs:<\/strong> Individual units of work defined inside a stage. For example, a <code>test<\/code> stage might contain two jobs running in parallel: <code>unit_tests<\/code> and <code>lint_check<\/code>.<\/li>\n\n\n\n<li><strong>Scripts:<\/strong> The actual command-line instructions (such as <code>npm install<\/code> or <code>npm test<\/code>) executed by the runner inside a job.<\/li>\n\n\n\n<li><strong>Runners:<\/strong> The agents that pick up jobs and execute their scripts inside isolated environments.<\/li>\n\n\n\n<li><strong>Artifacts:<\/strong> Files or directories generated by a job (such as compiled binaries, packaged archives, or test reports) that GitLab saves and passes to subsequent stages or makes available for download.<\/li>\n\n\n\n<li><strong>Cache:<\/strong> Temporary storage used to speed up future pipeline runs by preserving downloaded dependencies (like <code>node_modules<\/code> or Python virtual environments) between executions.<\/li>\n\n\n\n<li><strong>CI\/CD Variables:<\/strong> Key-value pairs injected into job environments at runtime, allowing you to store configuration values, API endpoints, and secret credentials outside your source code.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">How Code Moves Through a Pipeline<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Imagine a developer fixes a bug in a web application and pushes the commit to GitLab:<\/p>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li><strong>Build Stage:<\/strong> GitLab triggers a pipeline. A runner picks up the <code>build_app<\/code> job, installs dependencies, compiles the code, and saves the compiled output as an <strong>artifact<\/strong>.<\/li>\n\n\n\n<li><strong>Test Stage:<\/strong> Because the build succeeded, GitLab moves to the <code>test<\/code> stage. A runner downloads the build artifact and runs automated unit tests using <strong>CI\/CD variables<\/strong> to configure the test database connection.<\/li>\n\n\n\n<li><strong>Deploy Stage:<\/strong> Once all tests pass, GitLab starts the <code>deploy<\/code> stage. A runner takes the verified artifact and deploys it to a staging server.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">4. Prepare Your First Practice Project<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To make this tutorial easy to follow and reproduce, we will use a lightweight <strong>Node.js task-tracker API<\/strong> as our consistent sample application throughout the guide. Even if you primarily work with Python, Java, or Go, the GitLab CI\/CD concepts remain identical.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Access GitLab and Create a New Project<\/h3>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li>Log in to your GitLab account (either on GitLab.com or your organization&#8217;s self-managed GitLab instance).<\/li>\n\n\n\n<li>Click the <strong>+<\/strong> icon in the top navigation bar or select <strong>New project<\/strong> from your dashboard.<\/li>\n\n\n\n<li>Choose <strong>Create blank project<\/strong>.<\/li>\n\n\n\n<li>Name the project <code>gitlab-cicd-starter<\/code>.<\/li>\n\n\n\n<li>Set the <strong>Visibility Level<\/strong> to <strong>Private<\/strong>.<\/li>\n\n\n\n<li>Ensure <strong>Initialize repository with a README<\/strong> is checked, which automatically sets <code>main<\/code> as your <strong>default branch<\/strong>.<\/li>\n\n\n\n<li>Click <strong>Create project<\/strong>.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Understand Basic Repository Permissions<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In GitLab, your project role determines what actions you can take with pipelines:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Developer:<\/strong> Can push code to non-protected branches, trigger pipelines, and view job logs.<\/li>\n\n\n\n<li><strong>Maintainer:<\/strong> Can modify CI\/CD settings, configure runners, manage protected branches, and create protected CI\/CD variables.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Because you created this practice project, you automatically hold the <strong>Owner<\/strong> role, giving you full administrative access.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3: Add Sample Application Code<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Create three small files in the root of your repository (either via the GitLab web IDE or by cloning the repository locally and pushing):<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>1. <code>package.json<\/code><\/strong> (defines project metadata, dependencies, and scripts):<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">JSON<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n  \"name\": \"gitlab-cicd-starter\",\n  \"version\": \"1.0.0\",\n  \"description\": \"Sample application for learning GitLab CI\/CD\",\n  \"main\": \"app.js\",\n  \"scripts\": {\n    \"test\": \"node --test app.test.js\",\n    \"build\": \"node build.js\"\n  }\n}\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>2. <code>app.js<\/code><\/strong> (our core application module):<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">JavaScript<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function formatTask(title, completed = false) {\n  if (!title || typeof title !== 'string') {\n    throw new Error('Task title must be a non-empty string');\n  }\n  return {\n    title: title.trim(),\n    status: completed ? 'DONE' : 'PENDING'\n  };\n}\n\nmodule.exports = { formatTask };\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>3. <code>app.test.js<\/code><\/strong> (automated unit tests using Node&#8217;s built-in test runner):<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">JavaScript<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>const test = require('node:test');\nconst assert = require('node:assert');\nconst { formatTask } = require('.\/app');\n\ntest('formats a pending task properly', () =&gt; {\n  const result = formatTask('  Learn GitLab CI\/CD  ');\n  assert.deepStrictEqual(result, {\n    title: 'Learn GitLab CI\/CD',\n    status: 'PENDING'\n  });\n});\n\ntest('throws an error when title is empty', () =&gt; {\n  assert.throws(() =&gt; formatTask(''), \/Task title must be a non-empty string\/);\n});\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>4. <code>build.js<\/code><\/strong> (a simple build script that packages our application into a <code>dist\/<\/code> folder):<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">JavaScript<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>const fs = require('node:fs');\nconst path = require('node:path');\n\nconst distDir = path.join(__dirname, 'dist');\nif (!fs.existsSync(distDir)) {\n  fs.mkdirSync(distDir);\n}\n\nfs.copyFileSync(path.join(__dirname, 'app.js'), path.join(distDir, 'app.js'));\nfs.writeFileSync(\n  path.join(distDir, 'build-info.json'),\n  JSON.stringify({ builtAt: new Date().toISOString(), version: '1.0.0' }, null, 2)\n);\n\nconsole.log('Build completed successfully. Output written to dist\/.');\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Notice that this sample project requires zero external third-party packages yet supports realistic <code>npm run build<\/code> and <code>npm test<\/code> workflows.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">5. Check Runner Availability<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Before creating your pipeline configuration, verify that your project has access to an active GitLab Runner.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Runner Options and Executors<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>GitLab-Hosted Runners (Instance Runners):<\/strong> If you use GitLab.com, pre-configured runners are already available to execute your jobs immediately. They run inside fresh, isolated virtual machines or containers for each job.<\/li>\n\n\n\n<li><strong>Self-Managed Runners:<\/strong> Organizations hosting their own GitLab instances\u2014or teams needing access to internal networks, specialized hardware, or custom software\u2014install the GitLab Runner binary on their own servers.<\/li>\n\n\n\n<li><strong>Executors:<\/strong> Every runner uses an <em>executor<\/em> to determine how jobs run. The <strong>Docker executor<\/strong> is the most common because it launches a clean container image (such as <code>node:20-alpine<\/code>) for every job, ensuring reproducible environments. Other executors include <strong>Shell<\/strong> (runs directly on the host machine) and <strong>Kubernetes<\/strong> (spins up pods in a cluster).<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">How to Check Runner Status<\/h3>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li>Inside your <code>gitlab-cicd-starter<\/code> project, navigate to <strong>Settings &gt; CI\/CD<\/strong>.<\/li>\n\n\n\n<li>Expand the <strong>Runners<\/strong> section.<\/li>\n\n\n\n<li>Look under <strong>Instance runners<\/strong> (or <strong>Project runners<\/strong> \/ <strong>Group runners<\/strong>).<\/li>\n\n\n\n<li>Confirm that at least one runner displays a <strong>green circle<\/strong> next to its name, indicating it is online and ready to accept jobs.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">When a Project Needs Its Own Runner<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">You typically rely on shared or instance runners for standard builds and tests. You should register a dedicated project runner when:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Your jobs require access to firewalled internal databases or staging servers.<\/li>\n\n\n\n<li>Your builds demand high CPU, memory, or GPU resources not available on shared pools.<\/li>\n\n\n\n<li>Compliance policies prohibit running build workloads on shared infrastructure.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">If no green runner appears in your project settings, any pipeline you trigger will remain stuck in a <strong>Pending<\/strong> state until a runner is enabled or registered.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">6. Create the First .gitlab-ci.yml File<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">GitLab CI\/CD looks for a single file named <code>.gitlab-ci.yml<\/code> in the root directory of your repository. Note the leading dot in the filename and the <code>.yml<\/code> extension.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step-by-Step Creation<\/h3>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li>In your GitLab project, go to <strong>Code &gt; Repository<\/strong>.<\/li>\n\n\n\n<li>Click the <strong>+<\/strong> dropdown next to your branch name (<code>main<\/code>) and choose <strong>New file<\/strong>.<\/li>\n\n\n\n<li>Enter <code>.gitlab-ci.yml<\/code> as the <strong>Filename<\/strong>.<\/li>\n\n\n\n<li>Paste the following minimal working configuration into the editor:<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">YAML<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>default:\n  image: node:20-alpine\n\nstages:\n  - build\n  - test\n\nbuild_application:\n  stage: build\n  script:\n    - echo \"Starting application build...\"\n    - npm run build\n\ntest_application:\n  stage: test\n  script:\n    - echo \"Running automated unit tests...\"\n    - npm test\n<\/code><\/pre>\n\n\n\n<ol start=\"5\" class=\"wp-block-list\">\n<li>Scroll down, enter a commit message such as <code>Add initial .gitlab-ci.yml pipeline<\/code>, and click <strong>Commit changes<\/strong>.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">How This Configuration Works<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>default: image: node:20-alpine<\/code>:<\/strong> Tells the Docker runner to pull a lightweight Node.js 20 container image for every job in the pipeline so <code>node<\/code> and <code>npm<\/code> commands are available.<\/li>\n\n\n\n<li><strong><code>stages<\/code>:<\/strong> Declares the sequential order of execution. GitLab will run all jobs assigned to <code>build<\/code> first, followed by all jobs assigned to <code>test<\/code>.<\/li>\n\n\n\n<li><strong><code>build_application<\/code> and <code>test_application<\/code>:<\/strong> These are custom <strong>job names<\/strong>. You can name jobs descriptively to reflect what they do.<\/li>\n\n\n\n<li><strong><code>stage<\/code>:<\/strong> Links each job to one of the declared stages.<\/li>\n\n\n\n<li><strong><code>script<\/code>:<\/strong> A YAML list (indicated by <code>-<\/code> ) of shell commands executed in order. YAML relies strictly on <strong>2-space indentation<\/strong>\u2014never use tab characters, or GitLab will reject the file as invalid.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">As soon as you commit <code>.gitlab-ci.yml<\/code>, GitLab automatically detects the file and triggers your first pipeline.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">7. Follow the Pipeline From Start to Finish<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Navigate to <strong>Build &gt; Pipelines<\/strong> in the left sidebar to watch your pipeline run in real time.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Reading the Pipeline Interface<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Pipeline Status:<\/strong> Displayed as a badge on the left of each row. Common statuses include:\n<ul class=\"wp-block-list\">\n<li><strong>Pending:<\/strong> Waiting for an available runner.<\/li>\n\n\n\n<li><strong>Running:<\/strong> Currently executing jobs on a runner.<\/li>\n\n\n\n<li><strong>Passed (green checkmark):<\/strong> Every required job succeeded.<\/li>\n\n\n\n<li><strong>Failed (red X):<\/strong> At least one job exited with a non-zero error code.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Pipeline Graph:<\/strong> Click the pipeline status badge (e.g., <code>#1049281<\/code>) to open the visual pipeline graph. You will see columns representing your stages (<code>build<\/code> on the left, <code>test<\/code> on the right) with job pills inside each column.<\/li>\n\n\n\n<li><strong>Stage Order Execution:<\/strong> Observe that <code>test_application<\/code> stays in a <em>Created<\/em> or <em>Waiting<\/em> state until <code>build_application<\/code> turns green. If <code>build_application<\/code> fails, GitLab stops the pipeline immediately and skips the <code>test<\/code> stage.<\/li>\n\n\n\n<li><strong>Inspecting Job Logs:<\/strong> Click directly on the <code>build_application<\/code> job pill to open its terminal log. You will see the runner pulling the <code>node:20-alpine<\/code> image, cloning your repository at the exact commit SHA, executing <code>npm run build<\/code>, and printing <code>Job succeeded<\/code> at the bottom.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">How to Identify the First Failing Job<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">When a larger pipeline fails, avoid guessing what broke:<\/p>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li>Open the failed pipeline graph.<\/li>\n\n\n\n<li>Scan from left to right across the stages to locate the earliest red <strong>Failed<\/strong> job badge.<\/li>\n\n\n\n<li>Click that job to open its terminal output and scroll to the bottom (or search for <code>ERROR<\/code> or <code>exit code 1<\/code>) to see the exact command that failed.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">8. Add Automated Testing to the Workflow<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Running unit tests automatically on every commit catches bugs before they reach shared branches. Let&#8217;s enhance our <code>test<\/code> stage so it installs dependencies cleanly (when a <code>package-lock.json<\/code> is present), runs tests, and generates a machine-readable test report that GitLab can display directly in merge requests.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Update your <code>app.test.js<\/code> and <code>.gitlab-ci.yml<\/code> so Node outputs JUnit XML test reports, which GitLab parses natively:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">YAML<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>default:\n  image: node:20-alpine\n\nstages:\n  - build\n  - test\n\nbuild_application:\n  stage: build\n  script:\n    - npm run build\n\nunit_tests:\n  stage: test\n  script:\n    - node --test --test-reporter=junit --test-reporter-destination=junit.xml app.test.js\n  artifacts:\n    when: always\n    reports:\n      junit: junit.xml\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Key Testing Concepts Explained<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Installing Dependencies:<\/strong> In projects with third-party libraries in <code>package.json<\/code>, add <code>npm ci<\/code> (clean install from <code>package-lock.json<\/code>) before running your test command. <code>npm ci<\/code> is faster and stricter than <code>npm install<\/code> in CI environments.<\/li>\n\n\n\n<li><strong>Handling Test Failures:<\/strong> Whenever a test assertion fails, the test runner exits with a non-zero exit code (such as <code>1<\/code>). GitLab immediately marks the <code>unit_tests<\/code> job as <strong>Failed<\/strong> and prevents subsequent stages (such as <code>deploy<\/code>) from running.<\/li>\n\n\n\n<li><strong>Publishing Test Reports:<\/strong> Adding <code>artifacts: reports: junit: junit.xml<\/code> with <code>when: always<\/code> ensures that even if a test fails, GitLab uploads the XML report. You can then click the <strong>Tests<\/strong> tab on the pipeline page to inspect individual test pass\/fail counts and error stack traces without digging through raw console logs.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">9. Save and Reuse Build Outputs<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Each job in GitLab CI\/CD starts in a clean workspace. That means the <code>dist\/<\/code> directory generated by <code>build_application<\/code> disappears as soon as that job finishes unless you explicitly preserve it. GitLab provides two distinct mechanisms for managing files across jobs: <strong>Artifacts<\/strong> and <strong>Cache<\/strong>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Artifacts vs. Cache: Understanding the Difference<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Beginners often confuse artifacts and caches because both store files. However, they serve opposite purposes:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><td><strong>Feature<\/strong><\/td><td><strong>Artifacts<\/strong><\/td><td><strong>Cache<\/strong><\/td><\/tr><\/thead><tbody><tr><td><strong>Purpose<\/strong><\/td><td>Pass build outputs (compiled code, binaries, reports) <strong>between stages within the same pipeline<\/strong>.<\/td><td>Speed up future pipelines by reusing downloaded dependencies (<code>node_modules<\/code>, <code>.pip<\/code>) <strong>across separate pipeline runs<\/strong>.<\/td><\/tr><tr><td><strong>Reliability<\/strong><\/td><td>Guaranteed delivery to downstream jobs in later stages.<\/td><td>Best-effort optimization; jobs must still work if a cache is missing or cleared.<\/td><\/tr><tr><td><strong>Downloadable in UI?<\/strong><\/td><td>Yes, users can download artifacts from the pipeline interface.<\/td><td>No, caches are internal to runners.<\/td><\/tr><tr><td><strong>Expiration<\/strong><\/td><td>Controlled via <code>expire_in<\/code> (e.g., <code>1 week<\/code> or <code>30 days<\/code>).<\/td><td>Managed automatically by runner cache keys and policies.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Sharing Build Artifacts Between Jobs<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Here is how to configure <code>build_application<\/code> to save the <code>dist\/<\/code> directory as an artifact and verify its presence in a downstream job:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">YAML<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>default:\n  image: node:20-alpine\n\nstages:\n  - build\n  - test\n\nbuild_application:\n  stage: build\n  script:\n    - npm run build\n  artifacts:\n    paths:\n      - dist\/\n    expire_in: 1 week\n\nunit_tests:\n  stage: test\n  script:\n    - ls -la dist\/\n    - node --test app.test.js\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">When <code>unit_tests<\/code> starts, GitLab automatically downloads all artifacts from the preceding <code>build<\/code> stage before running <code>script<\/code>. Running <code>ls -la dist\/<\/code> confirms that <code>app.js<\/code> and <code>build-info.json<\/code> created during the <code>build<\/code> stage are ready for testing or packaging. Setting <code>expire_in: 1 week<\/code> keeps your GitLab storage clean by automatically removing temporary practice artifacts after seven days.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">10. Manage Pipeline Settings and Variables<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Hardcoding server addresses, environment names, or API keys directly inside <code>.gitlab-ci.yml<\/code> is both inflexible and dangerous\u2014anyone with read access to your repository could view your credentials in Git history. <strong>CI\/CD variables<\/strong> solve this problem by injecting values dynamically at runtime.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Types of CI\/CD Variables<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Predefined Variables:<\/strong> GitLab automatically injects dozens of built-in variables into every job, such as <code>$CI_COMMIT_BRANCH<\/code> (the current branch name), <code>$CI_COMMIT_SHORT_SHA<\/code> (the 8-character commit hash), and <code>$CI_PROJECT_NAME<\/code>.<\/li>\n\n\n\n<li><strong>Project and Group Variables:<\/strong> Custom variables configured in the GitLab UI under <strong>Settings &gt; CI\/CD &gt; Variables<\/strong>. Group variables are inherited by all projects inside a GitLab group.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Protecting and Masking Sensitive Credentials<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">When creating custom variables in <strong>Settings &gt; CI\/CD &gt; Variables<\/strong>, GitLab provides two critical security flags:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Protected:<\/strong> The variable is only exposed to pipelines running on <strong>protected branches<\/strong> (like <code>main<\/code>) or protected tags. Feature branches cannot access production secrets.<\/li>\n\n\n\n<li><strong>Masked:<\/strong> GitLab automatically scrubs the variable&#8217;s value from job logs, replacing it with <code>[MASKED]<\/code> so sensitive tokens are never printed in terminal output.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Example: Using Variables Safely in a Job<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Suppose you add a custom variable named <code>STAGING_API_TOKEN<\/code> (marked <strong>Protected<\/strong> and <strong>Masked<\/strong>) in your project settings. You can reference it alongside predefined variables in <code>.gitlab-ci.yml<\/code>:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">YAML<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>check_environment:\n  stage: test\n  variables:\n    APP_ENV: \"staging\"\n  script:\n    - echo \"Deploying project $CI_PROJECT_NAME on branch $CI_COMMIT_BRANCH\"\n    - echo \"Target environment is $APP_ENV\"\n    - echo \"Token length check passed\"\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Notice that <code>APP_ENV<\/code> is defined directly in YAML because <code>\"staging\"<\/code> is non-sensitive, while <code>STAGING_API_TOKEN<\/code> stays safely stored in GitLab&#8217;s encrypted project settings.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">11. Introduce Deployment With GitLab CI\/CD<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Once your application builds cleanly and passes automated tests, the final phase of a basic CI\/CD pipeline is deploying the build artifact to a target environment.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Learning Lab vs. Production Deployments<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In a <strong>practice lab<\/strong>, you often do not have a live cloud server connected to GitLab, so you simulate deployment steps (or deploy to an isolated test directory\/container) to verify artifact handoff and environment tracking. In a <strong>production environment<\/strong>, deployments involve SSH keys, cloud provider credentials (such as AWS OIDC or Kubernetes service accounts), zero-downtime rolling updates, and automated rollback strategies.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Illustrative Staging Deployment Configuration<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Add a <code>deploy<\/code> stage to your pipeline that runs only on the <code>main<\/code> branch, tracks the deployment in GitLab&#8217;s <strong>Operate &gt; Environments<\/strong> dashboard, and performs a post-deployment check:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">YAML<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>stages:\n  - build\n  - test\n  - deploy\n\n# ... build_application and unit_tests jobs from earlier ...\n\ndeploy_staging:\n  stage: deploy\n  environment:\n    name: staging\n    url: https:\/\/staging.example.internal\n  rules:\n    - if: $CI_COMMIT_BRANCH == \"main\"\n  script:\n    - echo \"Preparing deployment for commit $CI_COMMIT_SHORT_SHA...\"\n    - mkdir -p \/tmp\/staging_server\n    - cp -r dist\/* \/tmp\/staging_server\/\n    - echo \"Verifying deployed files...\"\n    - test -f \/tmp\/staging_server\/app.js\n    - cat \/tmp\/staging_server\/build-info.json\n    - echo \"Staging deployment verified successfully.\"\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">How These Deployment Controls Work<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>environment<\/code>:<\/strong> Registers <code>staging<\/code> inside GitLab&#8217;s Environments dashboard so your team can see which commit is currently deployed to staging.<\/li>\n\n\n\n<li><strong><code>rules: - if: $CI_COMMIT_BRANCH == \"main\"<\/code>:<\/strong> Ensures deployments happen only when code lands on the <code>main<\/code> branch, preventing experimental feature branches from overwriting your staging environment.<\/li>\n\n\n\n<li><strong>Manual Deployment Controls:<\/strong> If you want human approval before deploying (common for production releases), add <code>when: manual<\/code> to the job. GitLab will pause the pipeline before deployment and display a <strong>Play<\/strong> button in the UI.<\/li>\n\n\n\n<li><strong>Post-Deployment Verification:<\/strong> Checking that <code>app.js<\/code> exists and reading <code>build-info.json<\/code> (or running a <code>curl<\/code> health check against a live URL) confirms the deployment actually succeeded rather than silently failing.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">12. Explore Useful GitLab CI\/CD Features<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">After mastering your first three-stage pipeline, GitLab offers several powerful features to make workflows faster, cleaner, and easier to maintain:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>rules<\/code>:<\/strong> Replaces older <code>only<\/code>\/<code>except<\/code> keywords with flexible <code>if<\/code> expressions that control when jobs run based on branch names, merge requests, file changes, or custom variables.<\/li>\n\n\n\n<li><strong><code>needs<\/code>:<\/strong> Creates a Directed Acyclic Graph (DAG) allowing a job to start as soon as a specific earlier job finishes, rather than waiting for an entire stage to complete.<\/li>\n\n\n\n<li><strong>Parallel Jobs:<\/strong> Runs multiple jobs in the same stage simultaneously (such as <code>unit_tests<\/code>, <code>lint_code<\/code>, and <code>security_audit<\/code>), cutting total pipeline duration dramatically.<\/li>\n\n\n\n<li><strong>Manual Jobs (<code>when: manual<\/code>):<\/strong> Pauses execution until a team member explicitly triggers the job, ideal for production releases or destructive database migrations.<\/li>\n\n\n\n<li><strong>Scheduled Pipelines:<\/strong> Runs pipelines automatically on a cron schedule (configured under <strong>Build &gt; Pipeline schedules<\/strong>) for nightly regression suites or dependency updates.<\/li>\n\n\n\n<li><strong>Merge Request Pipelines:<\/strong> Runs dedicated validation checks on the combined result of a source branch and target branch before code is merged.<\/li>\n\n\n\n<li><strong>Reusable Configuration (<code>include<\/code>):<\/strong> Splits large <code>.gitlab-ci.yml<\/code> files into smaller, modular YAML templates stored locally or in a shared central repository.<\/li>\n\n\n\n<li><strong>Parent-Child Pipelines:<\/strong> Triggers downstream sub-pipelines from a main pipeline, useful for monorepos where frontend and backend services live in the same repository.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">13. Fix Common Problems During Your First Pipeline<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Even experienced engineers encounter pipeline errors. Knowing where to look turns frustrating failures into quick fixes.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. Invalid YAML Syntax or Incorrect Indentation<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Symptom:<\/strong> GitLab displays a red banner saying <em>Pipeline cannot be run: yaml invalid<\/em> immediately after committing.<\/li>\n\n\n\n<li><strong>Where to Look:<\/strong> Open <strong>Build &gt; Pipeline editor<\/strong> and click the <strong>Validate<\/strong> tab. GitLab highlights the exact line number with the syntax error.<\/li>\n\n\n\n<li><strong>How to Verify:<\/strong> Replace any tab characters with 2 spaces, ensure every list item starts with <code>-<\/code> , and confirm the Pipeline Editor shows <em>Simulation completed successfully<\/em>.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">2. No Active Runner Available<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Symptom:<\/strong> The pipeline stays stuck in <strong>Pending<\/strong> with a message stating <em>This job is stuck because you don&#8217;t have any active runners that can run this job<\/em>.<\/li>\n\n\n\n<li><strong>Where to Look:<\/strong> Go to <strong>Settings &gt; CI\/CD &gt; Runners<\/strong>.<\/li>\n\n\n\n<li><strong>How to Verify:<\/strong> Enable instance runners or verify that your project runner service is online (green indicator).<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">3. Missing Dependencies or Command Not Found<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Symptom:<\/strong> Job fails with <code>sh: npm: not found<\/code> or <code>Cannot find module '...'<\/code>.<\/li>\n\n\n\n<li><strong>Where to Look:<\/strong> Check the top of the job log to see which Docker image the runner used.<\/li>\n\n\n\n<li><strong>How to Verify:<\/strong> Ensure <code>image: node:20-alpine<\/code> (or your required language runtime) is specified and that <code>npm ci<\/code> runs before scripts requiring third-party libraries.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">4. Incorrect Script Commands<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Symptom:<\/strong> Job fails with <code>npm ERR! Missing script: \"test\"<\/code> or <code>No such file or directory<\/code>.<\/li>\n\n\n\n<li><strong>Where to Look:<\/strong> Inspect the exact command echoed in green inside the job log right before the error message.<\/li>\n\n\n\n<li><strong>How to Verify:<\/strong> Test the exact command locally in your terminal and ensure file paths match your repository&#8217;s folder structure (Linux runners are case-sensitive).<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">5. Permission Errors<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Symptom:<\/strong> Job fails with <code>Permission denied<\/code> when executing a shell script (such as <code>.\/deploy.sh<\/code>).<\/li>\n\n\n\n<li><strong>Where to Look:<\/strong> Check file permissions in your repository or the job log output.<\/li>\n\n\n\n<li><strong>How to Verify:<\/strong> Run <code>chmod +x deploy.sh<\/code> locally and commit the executable permission, or invoke it with <code>sh deploy.sh<\/code>.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">6. Missing Environment Variables<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Symptom:<\/strong> Deployment or API scripts fail because a variable resolves to an empty string.<\/li>\n\n\n\n<li><strong>Where to Look:<\/strong> Check <strong>Settings &gt; CI\/CD &gt; Variables<\/strong> to see if the variable is marked <strong>Protected<\/strong>.<\/li>\n\n\n\n<li><strong>How to Verify:<\/strong> If you are testing on a feature branch, a <strong>Protected<\/strong> variable will not be injected. Either uncheck <em>Protected<\/em> for non-sensitive variables or test on a protected branch.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">7. Failed Test Commands<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Symptom:<\/strong> The <code>test<\/code> stage turns red and downstream <code>deploy<\/code> jobs are skipped.<\/li>\n\n\n\n<li><strong>Where to Look:<\/strong> Open the failing test job log or click the <strong>Tests<\/strong> tab on the pipeline summary page.<\/li>\n\n\n\n<li><strong>How to Verify:<\/strong> Fix the failing application logic or test assertion, push a new commit, and confirm the test job turns green.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">8. Missing Artifacts<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Symptom:<\/strong> A job in <code>test<\/code> or <code>deploy<\/code> fails because <code>dist\/<\/code> does not exist.<\/li>\n\n\n\n<li><strong>Where to Look:<\/strong> Check the end of the <code>build<\/code> job log for the line <code>Uploading artifacts for successful job<\/code>.<\/li>\n\n\n\n<li><strong>How to Verify:<\/strong> Confirm the <code>paths:<\/code> entry under <code>artifacts:<\/code> matches the exact directory created by your build script.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">9. Unexpected Pipeline Execution Conditions<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Symptom:<\/strong> A job you expected to run did not appear in the pipeline graph at all.<\/li>\n\n\n\n<li><strong>Where to Look:<\/strong> Review the <code>rules:<\/code> block on that job and check which branch or event triggered the pipeline.<\/li>\n\n\n\n<li><strong>How to Verify:<\/strong> Confirm <code>$CI_COMMIT_BRANCH<\/code> matches your rule condition (for instance, <code>\"main\"<\/code> vs <code>\"master\"<\/code>).<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">14. Hands-On Challenge: Build a Complete Starter Pipeline<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Put everything you have learned together by building a complete end-to-end starter pipeline in your <code>gitlab-cicd-starter<\/code> repository.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Challenge Requirements<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Update your <code>.gitlab-ci.yml<\/code> file so a single push to <code>main<\/code> executes the following seven-step workflow:<\/p>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li><strong>Retrieve application code:<\/strong> Automatically handled by the GitLab Runner when each job starts.<\/li>\n\n\n\n<li><strong>Install required dependencies:<\/strong> Run <code>npm install --ignore-scripts<\/code> (or <code>npm ci<\/code> if you generate a <code>package-lock.json<\/code>) during preparation.<\/li>\n\n\n\n<li><strong>Run automated tests:<\/strong> Execute <code>app.test.js<\/code> in the <code>test<\/code> stage and generate a JUnit report.<\/li>\n\n\n\n<li><strong>Build the application:<\/strong> Run <code>npm run build<\/code> in the <code>build<\/code> stage to create the <code>dist\/<\/code> directory.<\/li>\n\n\n\n<li><strong>Save the build output as an artifact:<\/strong> Preserve <code>dist\/<\/code> for <code>1 day<\/code>.<\/li>\n\n\n\n<li><strong>Deploy to a test environment:<\/strong> Copy the <code>dist\/<\/code> artifact into <code>\/tmp\/test_env<\/code> inside a <code>deploy_test<\/code> job restricted to the <code>main<\/code> branch.<\/li>\n\n\n\n<li><strong>Verify the deployment result:<\/strong> Confirm <code>app.js<\/code> and <code>build-info.json<\/code> exist in <code>\/tmp\/test_env<\/code> and print the deployed version.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">Reference Solution<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Compare your solution against this complete configuration:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">YAML<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>default:\n  image: node:20-alpine\n\nstages:\n  - build\n  - test\n  - deploy\n\nbuild_job:\n  stage: build\n  script:\n    - npm install --ignore-scripts\n    - npm run build\n  artifacts:\n    paths:\n      - dist\/\n    expire_in: 1 day\n\ntest_job:\n  stage: test\n  script:\n    - node --test --test-reporter=junit --test-reporter-destination=junit.xml app.test.js\n  artifacts:\n    when: always\n    reports:\n      junit: junit.xml\n\ndeploy_test:\n  stage: deploy\n  environment:\n    name: testing\n  rules:\n    - if: $CI_COMMIT_BRANCH == \"main\"\n  script:\n    - mkdir -p \/tmp\/test_env\n    - cp -r dist\/* \/tmp\/test_env\/\n    - test -f \/tmp\/test_env\/app.js\n    - test -f \/tmp\/test_env\/build-info.json\n    - cat \/tmp\/test_env\/build-info.json\n    - echo \"Deployment verification complete.\"\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Expected Stage Outcomes &amp; Verification Checklist<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Build Stage (<code>build_job<\/code>):<\/strong> Exits with status <code>0<\/code> and displays <code>Uploading artifacts for successful job<\/code> in the job log.<\/li>\n\n\n\n<li><strong>Test Stage (<code>test_job<\/code>):<\/strong> Runs both unit tests, passes, and populates the <strong>Tests<\/strong> tab in the GitLab pipeline view.<\/li>\n\n\n\n<li><strong>Deploy Stage (<code>deploy_test<\/code>):<\/strong> Executes only on <code>main<\/code>, verifies both files exist in <code>\/tmp\/test_env<\/code>, and registers a deployment under <strong>Operate &gt; Environments &gt; testing<\/strong>.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Use this checklist to confirm your pipeline is working properly:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>[ ] <code>.gitlab-ci.yml<\/code> passes validation in the GitLab Pipeline Editor.<\/li>\n\n\n\n<li>[ ] All three stages (<code>build<\/code>, <code>test<\/code>, <code>deploy<\/code>) appear in sequential order in the pipeline graph.<\/li>\n\n\n\n<li>[ ] You can download <code>dist\/<\/code> directly from the <code>build_job<\/code> artifacts panel in the GitLab UI.<\/li>\n\n\n\n<li>[ ] Intentionally breaking an assertion in <code>app.test.js<\/code> causes <code>test_job<\/code> to fail and blocks <code>deploy_test<\/code> from running.<\/li>\n\n\n\n<li>[ ] Reverting the broken test restores a green pipeline across all stages.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">15. Develop Your GitLab CI\/CD Skills Further<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Once you feel comfortable writing basic YAML pipelines, you can expand your automation capabilities step by step rather than trying to adopt every advanced tool on day one:<\/p>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li><strong>Pipeline Optimization and Caching:<\/strong> Add dependency caching (<code>cache:<\/code>) and use <code>needs:<\/code> to run independent lint, test, and build jobs concurrently so feedback reaches developers faster.<\/li>\n\n\n\n<li><strong>Container Image Builds:<\/strong> Learn how to build Docker images inside GitLab CI\/CD and push them to the built-in <strong>GitLab Container Registry<\/strong> tagged with <code>$CI_COMMIT_SHORT_SHA<\/code>.<\/li>\n\n\n\n<li><strong>Automated Security Scanning:<\/strong> Integrate Static Application Security Testing (SAST), dependency scanning, and secret detection templates to catch vulnerabilities before code is merged.<\/li>\n\n\n\n<li><strong>Reusable Templates (<code>include<\/code>):<\/strong> Refactor repeated job definitions across multiple repositories into centralized CI\/CD templates so teams maintain one standard pipeline definition.<\/li>\n\n\n\n<li><strong>Infrastructure as Code (IaC):<\/strong> Automate Terraform or OpenTofu plan-and-apply workflows inside GitLab pipelines with manual approval gates for infrastructure changes.<\/li>\n\n\n\n<li><strong>Kubernetes Deployments:<\/strong> Connect GitLab to a Kubernetes cluster using the GitLab Agent for Kubernetes to perform automated rolling deployments and review apps for every merge request.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">16. Conclusion: Turn Your First Pipeline Into a Learning Foundation<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Building your first working pipeline is a major milestone in understanding modern DevOps practices. In this <strong>GitLab CI\/CD Getting Started Guide<\/strong>, you learned how GitLab CI\/CD orchestrates workflows while GitLab Runners execute jobs, how to structure <code>.gitlab-ci.yml<\/code> using stages and scripts, how to automate unit tests, how to pass build outputs via artifacts, and how to secure configurations with protected and masked CI\/CD variables. Every complex enterprise delivery pipeline is built from these exact same primitives. Keep experimenting with your starter repository\u2014try adding a code linting job, creating a feature branch to see how <code>rules<\/code> behave on merge requests, or intentionally breaking a step to practice reading job logs. Consistent hands-on practice is the fastest way to turn basic YAML files into reliable, production-ready automation.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. Introduction: Your First Step Into GitLab CI\/CD Software development becomes significantly slower and more error-prone when teams rely on manual steps to build, test, and release&#8230; <\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5743","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/posts\/5743","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/comments?post=5743"}],"version-history":[{"count":1,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/posts\/5743\/revisions"}],"predecessor-version":[{"id":5745,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/posts\/5743\/revisions\/5745"}],"wp:attachment":[{"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/media?parent=5743"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/categories?post=5743"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/tags?post=5743"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}