- Classentral
- DevOps with GitLab CI Course - Build Pipelines and Deploy to AWS - YouTube
- Learn GitLab with tutorials GitLab
- Run Playwright Tests via GitLab
- ⌨️ Lesson 1 - Welcome (0:00:00)
- ⌨️ Lesson 2 - Your first GitLab project (0:03:03)
- ⌨️ Lesson 3 - Your first pipeline (0:13:00)
- ⌨️ Lesson 4 - Help, my pipeline is not working (0:23:32)
- ⌨️ Lesson 5 - What is YAML? (0:26:22)
- ⌨️ Lesson 6 - What is a shell? (0:35:12)
- ⌨️ Lesson 7 - GitLab architecture (0:37:50)
- ⌨️ Lesson 8 - Pipeline stages (0:43:14)
- Create GitLab account
- Create private project
- Change settings > Preferences > Syntax highlighting > Monokai
- On: Render whitespace characters in the web IDE
- Create new file
.gitlab-ci.yml
- Go to Build > Pipelines > Run pipeline
- Check pipeline logs
Push an existing Git repository
cd existing_repo
git remote add origin https://gitlab.com/mzn2/gitlabci.git
git branch -M main
git push -uf origin main
test:
script: echo "Hello world"
- Add commands to write text file
- By default pipeline uses Ruby Docker image
- Add alternative Docker image - Linux
alpine
- Commit changes
- Check pipeline logs
build laptop:
image: alpine
script:
- echo "Building laptop"
- mkdir build
- touch build/$BUILD_FILE_NAME
- echo "Mainboard" >> build/$BUILD_FILE_NAME
- cat build/$BUILD_FILE_NAME
- echo "Keyboard" >> build/$BUILD_FILE_NAME
- cat build/$BUILD_FILE_NAME
Output
Running with gitlab-runner 16.6.0~beta.105.gd2263193 (d2263193)
on blue-2.saas-linux-small-amd64.runners-manager.gitlab.com/default XxUrkriX, system ID: s_f46a988edce4
feature flags: FF_USE_IMPROVED_URL_MASKING:true
Resolving secrets
00:00
Preparing the "docker+machine" executor
00:05
Using Docker executor with image alpine ...
Pulling docker image alpine ...
Using docker image sha256:f8c20f8bbcb684055b4fea470fdd169c86e87786940b3262335b12ec3adef418 for alpine with digest alpine@sha256:51b67269f354137895d43f3b3d810bfacd3945438e94dc5ac55fdac340352f48 ...
Preparing environment
00:01
Running on runner-xxurkrix-project-53471482-concurrent-0 via runner-xxurkrix-s-l-s-amd64-1704186592-2d594c12...
Getting source from Git repository
00:01
Fetching changes with git depth set to 20...
Initialized empty Git repository in /builds/mzn2/gitlabci/.git/
Created fresh repository.
Checking out 341525e5 as detached HEAD (ref is main)...
Skipping Git submodules setup
$ git remote set-url origin "${CI_REPOSITORY_URL}"
Executing "step_script" stage of the job script
00:00
Using docker image sha256:f8c20f8bbcb684055b4fea470fdd169c86e87786940b3262335b12ec3adef418 for alpine with digest alpine@sha256:51b67269f354137895d43f3b3d810bfacd3945438e94dc5ac55fdac340352f48 ...
$ echo "Building laptop"
Building laptop
$ mkdir build
$ touch build/$BUILD_FILE_NAME
$ echo "Mainboard" >> build/$BUILD_FILE_NAME
$ cat build/$BUILD_FILE_NAME
Mainboard
$ echo "Keyboard" >> build/$BUILD_FILE_NAME
$ cat build/$BUILD_FILE_NAME
Mainboard
Keyboard
Cleaning up project directory and file based variables
00:01
Job succeeded
- Missing colon after job in yml file
- Missing space between dash and command
- Incorrect levele indentation (dfault 4 spaces )
yaml example
person:
name: John
age: 23
hobbies:
- sports
- YouTube
- hiking
address:
street: 123 Mayfield Ave.
experience:
- title: Junior Dev
period: 2000-2005
- title: Senior Dev
period: since 2005
It is important to use defined keywords and definitions.
GitLab runner has relatively simple installation. Can be run even on laptop.
- GitLab project > Settings > Runners
Shared runners are shared between all GitLab users. F
variables:
ENV: 'dev'
stages:
- setup
- test
setup data:
stage: setup
script:
- echo "Run script from setup"
run_playwright_smoke_tests:
stage: test
image: mcr.microsoft.com/playwright:v1.41.1-jammy
script:
- echo "Run script with $ENV environment from test stage"
Pipeline failed: Exit code - 1
Try to check the last command executing before fail occured. What is the Docker image used?
Job artifacts allow sharing outputs between different jobs in pipeline. For example files.
Use artifacts
and paths
to create artifact so that it can be used in other pipeline jobs.
build laptop:
...
artifacts:
paths:
- build
stages:
- build
- test
build laptop:
image: alpine
stage: build
script:
- echo "Building a laptop"
- mkdir build
- touch build/$BUILD_FILE_NAME
- echo "Mainboard" >> build/$BUILD_FILE_NAME
- cat build/$BUILD_FILE_NAME
- echo "Keyboard" >> build/$BUILD_FILE_NAME
artifacts:
paths:
- build
test laptop:
image: alpine
stage: test
script:
- test -f build/$BUILD_FILE_NAME
Use grep
to test contents of the file contain expected word so that this can be used to verify that code change does not break functionality.
- grep "Display" build/$BUILD_FILE_NAME
Use variables
as a global variable to specify file name so that file name can be changed in one place only and take effect in multiple parts of pipeline.
stages:
- build
- test
variables:
BUILD_FILE_NAME: laptop.txt
build laptop:
image: alpine
stage: build
script:
- echo "Building a laptop"
- mkdir build
- touch build/$BUILD_FILE_NAME
- echo "Mainboard" >> build/$BUILD_FILE_NAME
- cat build/$BUILD_FILE_NAME
- echo "Keyboard" >> build/$BUILD_FILE_NAME
artifacts:
paths:
- build
test laptop:
image: alpine
stage: test
script:
- test -f build/$BUILD_FILE_NAME
variables:
ENV: 'basewcdev'
CI: 'true'
playwright.config.ts
{
video: retain-on-failure,
headless: process.env.CI === 'true' ? true : false,
}