Gitlab - 3.3.4 whriting of the first pipeline

This lesson walks through writing your very first GitLab CI/CD pipeline. Two prerequisites: first, the application code must already be hosted in a Git repository (we have one). Second, you need a .gitlab-ci.yml file at the root of the repository. That YAML file defines the structure and order of your jobs, the scripts to run, dependencies, the tests to execute before deployment, the deployment target, and so on. In short, it defines your full pipeline end-to-end with step-by-step instructions.

Creating .gitlab-ci.yml from the GitLab UI

You can create the YAML file from your local system and push it to GitLab the same way we did with hello.py, or directly from the GitLab UI. The second option is easier for now. From the project dashboard, select a branch, click New file, and name it exactly .gitlab-ci.yml — the file name matters because GitLab only looks for this name to detect a pipeline (unless changed in project settings). From the file template dropdown you could pick a starter, but we will write ours from scratch.

Defining a single job

Every pipeline configuration starts by defining at least one job. A job is mandatory, and it starts with its name. Inside it, the stage keyword is optional — if not specified, GitLab places the job in the default test stage. The mandatory script keyword lists the commands to execute. Here is the minimal pipeline we will use:

job to run code:
  stage: test
  script:
    - python hello.py

We defined a single job that simply executes python hello.py. In real projects you typically define many jobs — almost unlimited — and we will see more of them in the next sections.

Committing and watching the pipeline run

With the pipeline defined, commit the file targeting the dev1 branch and confirm. As soon as GitLab notices a .gitlab-ci.yml in the repository, it starts running the pipeline automatically — no manual trigger required. Open the CI/CD section: the pipeline status is running.

The pipelines list page shows every pipeline, its status, who triggered it, etc., with a search bar to filter by author, branch, tag or status. On the right you can see how long each pipeline ran. Clicking a pipeline opens its details. Because pipelines can become complex graphs of sequential and parallel jobs, GitLab provides a visual graph view. Our pipeline has a single block — job to run code — but as you add jobs they will appear here in the order defined in your YAML. That is your first running pipeline. See you in the next video.

Summary

This lesson covers the fundamentals of writing your first GitLab CI/CD pipeline by creating a .gitlab-ci.yml configuration file. You'll learn the essential prerequisites, the structure of a pipeline configuration, and how to define jobs with stages and scripts. The lesson demonstrates a practical example of creating a simple pipeline that automatically triggers when code is committed and pushed to the repository, with guidance on monitoring execution through the GitLab dashboard.

Key points

  • A .gitlab-ci.yml file in the repository root is required to enable and define GitLab CI/CD pipelines
  • Pipelines are automatically triggered whenever code is committed and the .gitlab-ci.yml file is detected in the repository
  • A pipeline must contain at least one job definition with a mandatory name and script section that specifies executable commands
  • Jobs can be organized into stages using the 'stage' keyword; if omitted, GitLab defaults to the 'test' stage
  • The .gitlab-ci.yml file can be created either locally and pushed via Git, or directly through the GitLab web interface
  • Pipeline status, execution history, and visual flow can be monitored through the GitLab CI/CD dashboard with pipeline graphs

FAQ

What is the minimum requirement for a GitLab CI/CD pipeline to execute?

The minimum requirement is a .gitlab-ci.yml file in the repository root containing at least one job definition with a name and a mandatory script section that specifies what commands to execute.

How can you create a .gitlab-ci.yml file in GitLab?

You can either create it locally on your system and push it to the repository using Git commands, or create it directly through the GitLab web interface by clicking the 'New file' button in the project dashboard.

Are pipeline stages mandatory when defining a job?

No, the stage keyword is optional. If you don't specify a stage, GitLab automatically assigns the job to the default 'test' stage. Full course sections cover how to properly define and order multiple stages in complex pipelines.