Your first GitLab pipeline
Stages, jobs and a runner, from a green pipeline to a red one and back.
cd ~/lab && curl -fsSLO https://secopslog.com/lab-files/ci-gitlab/glbasics.tar.gz && tar -xzf glbasics.tar.gz, which creates ~/lab/glbasics/. SHA-256: dd8f4d165a2d07155248b4774611a504a9383c9306405ed8d8e1a9b62ca2074aA GitLab project has a merge request button, a pipeline badge that is green most days, and a file called .gitlab-ci.yml that one person wrote two years ago. Nobody else quite knows what runs when you push. This course starts by making that file ordinary: what a pipeline is, where its jobs run, and how to read one that failed.
Then it treats the pipeline as something worth attacking, because it is. A pipeline holds deploy credentials, builds what you ship, and runs code that anyone with push access can change. Most of the course is about keeping those three facts under control.
The lab
Everything runs in containers inside a disposable Linux VM with Docker Engine. If you took the Docker or Jenkins courses, reuse that lab VM. If not, the first lesson of Docker for beginners ("What Docker is, and why") sets one up with a script that also installs the tools these labs call. GitLab needs memory: give the VM 4 CPUs and at least 6 GB, and in this lab GitLab itself settled at about 2.5 GB. Each lesson has a download link for its files, with the command that fetches them inside the VM into ~/lab/<lesson>/. Check the tools first:
If a line says MISSING, install it with sudo apt-get install -y git jq curl openssl. Then start GitLab. The first start pulls about 1.6 GB and then takes several minutes while GitLab configures itself, so expect to wait:
# Lab GitLab: GitLab CE and one Runner, pinned by digest, published only on the VM's loopback.name: lab-gitlabservices:gitlab:image: gitlab/gitlab-ce:19.5.3-ce.0@sha256:6863d156a1a477bd6f69fc674b671d0163cd8b06bf63bb17cc4a4a803b78b27ccontainer_name: lab-gitlabhostname: gitlabshm_size: 256menvironment:GITLAB_ROOT_PASSWORD: ${GITLAB_ROOT_PASSWORD:?run ./up.sh}# Small-instance settings: one Puma process, few Sidekiq threads, no bundled monitoring.GITLAB_OMNIBUS_CONFIG: |external_url 'http://gitlab:8929'puma['worker_processes'] = 0sidekiq['concurrency'] = 5prometheus_monitoring['enable'] = falsegitlab_kas['enable'] = falsegitlab_rails['usage_ping_enabled'] = falsegitlab_rails['gitlab_shell_ssh_port'] = 2222gitlab_rails['initial_shared_runners_registration_token'] = nilregistry['enable'] = falseports: ["127.0.0.1:8929:8929"]volumes:- lab-gitlab-config:/etc/gitlab- lab-gitlab-data:/var/opt/gitlab- lab-gitlab-logs:/var/log/gitlabhealthcheck:test: ["CMD", "curl", "-fs", "-o", "/dev/null", "http://localhost:8929/users/sign_in"]interval: 10sstart_period: 900sretries: 6runner:image: gitlab/gitlab-runner:alpine-v19.5.3@sha256:25adb59339aebbee89050b2d3fd0d193a30c1860c70fd4d98d1c8b1e154914a3container_name: lab-gitlab-runnervolumes:- lab-runner-config:/etc/gitlab-runner# Lab only: the Docker executor starts job containers through the host's Docker socket,# which makes the runner root on this VM. The runner isolation lesson takes this apart.- /var/run/docker.sock:/var/run/docker.sockvolumes:lab-gitlab-config:lab-gitlab-data:lab-gitlab-logs:lab-runner-config:
Two containers. gitlab is GitLab Community Edition 19.5.3, the free, self-managed edition, so every feature this course uses is one you can run yourself without a licence. runner is GitLab Runner, the separate program that actually runs jobs. up.sh created a random root password and an API token for root, both in .env, readable only by you. The course scripts talk to GitLab through that token. That is a lab shortcut: real automation uses a project or group access token with the smallest scope and an expiry, never a root token, and a real server runs over HTTPS, because job and runner tokens cross that connection.
GITLAB_OMNIBUS_CONFIG settings shrink GitLab for a lab: one Puma process, few Sidekiq threads, no bundled monitoring. Don't copy them to a server people depend on. The runner also mounts the host's Docker socket, which makes it root on the VM. The runner isolation lesson shows what that allows, and in production a runner never shares a host with GitLab.Open the web UI
GitLab listens only on the VM's loopback address. With Lima, open http://127.0.0.1:8929 on your computer, because Lima forwards loopback ports by default. With Multipass, forward the port over SSH as the Jenkins course shows, using port 8929. Sign in as root with the password from grep GITLAB_ROOT_PASSWORD .env. Each project has a Build menu with Pipelines and Jobs, and that's where the logs from this course live.
A first pipeline
The sample app is one function and one test. The pipeline is the file next to them:
# Two stages: a fast lint, then the tests. Every job runs in a fresh container from this image.default:image: secopslog-py:3.15stages:- lint- testlint:stage: lintscript:- ruff check .test:stage: testscript:- python -m pytest -q
A job is a name with a script: shell commands run in order, and the first one that exits non-zero fails the job. stages put jobs in order: every job in lint must succeed before any job in test starts. default: image says which container image every job runs in, here a Python image with pytest and ruff already installed, built by up.sh so jobs don't download anything. seed.sh creates the project and pushes the folder, and the push starts the pipeline. pipeline.sh waits for it and prints each job's log, without the runner's preparation lines:
Each job ran in a fresh container. The runner keeps a working copy of the repository between jobs, but before each job it checks out the commit and deletes every file Git doesn't track (git clean -ffdx by default), so the lint job's leftovers were gone before test started. Nothing carries over from one job to the next unless you ask for it, which is the subject of the artifacts lesson. The API has the same facts in a form scripts can use:
source=push says why the pipeline exists. Later lessons meet other sources (merge_request_event, api, schedule), and rules can treat them differently.
Break it
Change + to - and push, as someone in a hurry might:
Read a failed pipeline from the bottom up. ERROR: Job failed: exit code 1 is the runner reporting that the script failed. Above it, pytest says what failed: assert 0 == 4. lint still passed, because the code is valid Python. It is only wrong. Fix it:
Hands-on
Start again with a fresh project: ./seed.sh app app/ deletes the project and its history and pushes the folder again. Add a second job, format, to the lint stage that runs ruff format --check ., and change calc.py to def add(a,b): (no space after the comma). Push both with ./commit.sh app/ "format job" and run ./pipeline.sh app/. Which jobs ran, which failed, and what happened to test? Finish with ./down.sh. A worked version is in solutions/.
What you should see: two jobs ran in the lint stage. lint passed with All checks passed!, because the code is still valid. format failed, and ruff format --check printed the diff it wants, def add(a,b): becoming def add(a, b):. test was skipped: a failed job in one stage stops the later stages, so the tests never ran. The pipeline failed even though nothing was functionally wrong, which is what a format check is for.
Remember
A job is a script in a fresh container, and a stage waits for the one before it. Read failures from the bottom up: the runner's ERROR line, then the tool's own message above it.
lint and test. The only lint job fails. What happens to the test jobs?pip install -r requirements.txt and then pytest. The next job, in a later stage, runs pytest again and fails with "No module named flask". Why?script run?