Course contentsShow
← Cloud and Infrastructure
Lesson 1730 of 2,98936. GitLab CI/CDFree lesson

Defining Your First Job

Create a simple job with a script section to understand the fundamental unit of work in GitLab CI.

Defining Your First Job

What you'll learn: How to create the fundamental unit of work in GitLab CI/CD—a job with a script section.

In GitLab CI, a job is the smallest executable unit that performs actual work in your pipeline. Think of it like a single task on your to-do list: specific, actionable, and complete. Every job must contain a script section that tells the runner what commands to execute.

The Basic Job Structure

A job in your .gitlab-ci.yml file has a name (which you choose) and at minimum requires a script section. The script contains one or more shell commands that run sequentially.

build-job:
  script:
    - echo "Hello from my first GitLab job!"
    - echo "This job is running successfully"

In this example, build-job is the job name. The script section lists two commands. When a GitLab Runner picks up this job, it executes these commands line by line in a fresh environment.

How It Works

When you commit this .gitlab-ci.yml file to your repository, GitLab detects it and automatically creates a pipeline. The runner assigned to execute your job will:

  1. Spin up an execution environment (typically a container or VM)
  2. Execute each command in the script section in order
  3. Report success if all commands exit with code 0, or failure otherwise

Each line in the script is a separate shell command. If any command fails (returns a non-zero exit code), the entire job fails and the pipeline stops.

Key Takeaway: A GitLab CI job is defined by a unique name and a script section containing the shell commands to execute—this is your pipeline's fundamental building block.