.gitlab_ci.yml file: `
- User
.gitlab_ci.yml file:
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
.gitlab_ci.yml file:
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
You're about to dive into the wonderful world of Continuous Integration and Continuous Deployment (CI/CD) with GitLab!
The .gitlab-ci.yml file is the heart of GitLab CI/CD, a YAML file that lives in the root of your repository and defines the CI/CD pipeline for your project. Here's a breakdown of the file structure, common keywords, and a simple example to get you started.
File Structure
---
stages:
- stage1
- stage2
- ...
variables:
KEY: "value"
ANOTHER_KEY: "another value"
job1:
stage: stage1
script:
- command1
- command2
...
job2:
stage: stage2
script:
- command3
- command4
...
Let's go over the main sections:
stages: Defines the stages of your pipeline. A stage is a logical grouping of jobs that run sequentially. Common stages are: build, test, deploy.variables: Key-value pairs that can be used throughout the pipeline. Useful for storing secrets, URLs, or other config values.job (e.g., job1, job2): A job represents a single task in the pipeline (e.g., run tests, build a Docker image). Each job:
stage.script section, which contains the commands to execute.Common Job Keywords
stage: The stage this job belongs to.script: The commands to run for this job (array of strings).before_script and after_script: Run commands before/after the main script.tags: Specify runners (agents that execute jobs) with matching tags.allow_failure: If true, the job can fail without failing the pipeline (default: false).when: Run the job on_success (default), on_failure, always, or manual (wait for human trigger).only and except: Limit job execution to specific branches, tags, or variables (e.g., only: [main]).artifacts: Define files or directories to save and retrieve between jobs (e.g., build outputs).cache: Paths to cache, so they're preserved between pipeline runs (e.g., dependencies).Simple Example
---
stages:
- build
- test
- deploy
variables:
APP_NAME: "my-awesome-app"
build_app:
stage: build
script:
- echo "Building $APP_NAME"
- mkdir build
- touch build/index.html
artifacts:
paths:
- build/
unit_tests:
stage: test
script:
- echo "Running unit tests"
- ls build/ # uses artifact from build_app job
- ./run-tests.sh
deploy_to_prod:
stage: deploy
script:
- echo "Deploying to production"
- scp -r build/* user@prod-server:/var/www/html/
only:
- main # only run this job on the main branch
when: manual # wait for a human to trigger the deploy
Here's what happens in this pipeline:
build, test, and deploy.build_app job runs first (in the build stage), creates a build directory, and generates an empty index.html. The build directory is saved as an artifact.unit_tests job (in the test stage) runs next. It lists the contents of the build directory (thanks to the artifact) and executes a fictional test script.deploy_to_prod job waits in the deploy stage. Since it's set to when: manual, a human must click the "Play" button in GitLab CI/CD to deploy the build directory to the production server only when the pipeline runs on the main branch.Tips & Next Steps
.gitlab-ci.yml file using the GitLab CI/CD "Lint" tool (in the GitLab UI, go to CI/CD > Pipelines > Lint)..gitlab-ci.yml reference.Now it's your turn! Share your project details (tech stack, what you want to achieve with CI/CD), and I'll help you craft a more tailored .gitlab_ci.yml file.
default:
image: debian:testing
tags:
- trixie
stages:
- build
- test
- generate
- lava
check devicetrees:
stage: build
tags:
- ultra-heavyweight
variables:
DEBIAN_FRONTEND: noninteractive
GIT_SUBMODULE_STRATEGY: normal
ARCH: arm64
DEFCONFIG: defconfig
CROSS_COMPILE: aarch64-linux-gnu-
DUT: rockchip/rk3588s-rock-5a.dtb rockchip/rk3588-rock-5b.dtb rockchip/rk3588-evb1-v10.dtb rockchip/rk3576-armsom-sige5.dtb
before_script:
- apt update
- apt install -y devscripts
build-essential
crossbuild-essential-arm64
bc
bison
flex
swig
python3-dev
python3-pip
python3-setuptools
yamllint
- pip3 install --break-system-packages dtschema
script:
- make $DEFCONFIG
- make -j$(nproc) dt_binding_check
- make -j$(nproc) CHECK_DTBS=y $DUT 2> dt-warnings.txt
- if [[ $(cat dt-warnings.txt | wc -l) > 0 ]]; then cat dt-warnings.txt; exit 42; fi
allow_failure:
exit_codes:
- 42
.build debian package:
stage: build
tags:
- ultra-heavyweight
cache:
when: on_success
key: $CI_COMMIT_REF_SLUG
paths:
- ccache
variables:
DEBIAN_FRONTEND: noninteractive
GIT_SUBMODULE_STRATEGY: normal
ARCH: amd64
DEFCONFIG: defconfig
CCACHE_BASEDIR: $CI_PROJECT_DIR
CCACHE_DIR: $CI_PROJECT_DIR/ccache
before_script:
- dpkg --add-architecture arm64
- apt update
- apt install -y devscripts
build-essential
crossbuild-essential-arm64
bc
bison
ccache
flex
rsync
kmod
cpio
libelf-dev
libssl-dev
libssl-dev:arm64
# Setup ccache
- export PATH="/usr/lib/ccache:$PATH"
- ccache -s
script:
- make $DEFCONFIG
- ./scripts/config -e WLAN -e WLAN_VENDOR_BROADCOM -m BRCMUTIL -m BRCMFMAC
-e BRCMFMAC_PROTO_BCDC -e BRCMFMAC_PROTO_MSGBUF
-e BRCMFMAC_USB
-e WLAN_VENDOR_REALTEK -m RTW89 -m RTW89_CORE
-e DYNAMIC_DEBUG
-m RTW89_PCI -m RTW89_8825B -m RTW89_8852BE
-m BINFMT_MISC
-m XFS_FS -m EROFS_FS -m F2FS_FS
-m EXFAT_FS -m ISO9660_FS
- make -j$(nproc) $ADDITIONAL_BUILD_CMD bindeb-pkg
- mkdir artifacts && dcmd mv ../*.changes artifacts/
artifacts:
paths:
- artifacts
build arm64 debian package:
extends: .build debian package
variables:
ARCH: arm64
CROSS_COMPILE: aarch64-linux-gnu-
ADDITIONAL_BUILD_CMD: KBUILD_IMAGE=arch/arm64/boot/Image
generate tests:
image: debian:trixie-slim
stage: generate
tags:
- lightweight
variables:
GIT_STRATEGY: fetch
GIT_DEPTH: "1"
needs:
- "build arm64 debian package"
before_script:
- apt update
- apt install -y wget
script:
- mkdir deb
- "for x in artifacts/linux-image*.deb ; do dpkg -x ${x} deb ; done"
- cp deb/boot/vmlinuz* vmlinuz
- mkdir -p deb/lib/firmware/arm/mali/arch10.8
- wget -O deb/lib/firmware/arm/mali/arch10.8/mali_csffw.bin "https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git/plain/arm/mali/arch10.8/mali_csffw.bin"
- tar -f modules.tar.gz -C deb -c -z -v lib/modules lib/firmware
- mkdir dtbs
- cp -r deb/usr/lib/linux-image*/* dtbs
- sed -i s,%%KERNEL_BUILD_JOB%%,${CI_JOB_ID},g lava/rock5b-testjob.yaml
- sed -i s,%%KERNEL_BUILD_JOB%%,${CI_JOB_ID},g lava/sige5-testjob.yaml
artifacts:
paths:
- vmlinuz*
- modules.tar.gz
- dtbs
- lava/rock5b-testjob.yaml
- lava/sige5-testjob.yaml
lava rock5b test:
stage: lava
environment: rock5b
tags:
- lava-runner
script:
- submit lava/rock5b-testjob.yaml
needs:
- "generate tests"
artifacts:
when: always
paths:
- "*"
reports:
junit: "*_junit.xml"
lava sige5 test:
stage: lava
environment: sige5
tags:
- lava-runner
script:
- submit lava/sige5-testjob.yaml
needs:
- "generate tests"
artifacts:
when: always
paths:
- "*"
reports:
junit: "*_junit.xml"
Let's dive into the kernel build process step by step, as if you're building it manually in a terminal session. We'll reference the .gitlab-ci.yml file for each command.
Building the Kernel (amd64 and arm64)
The kernel build process is defined in two jobs:
.build debian package (a template job)build arm64 debian package (extends the template job with arm64 specifics)We'll cover both builds. Let's start with the common steps from the template job .build debian package, and then highlight the differences for build arm64 debian package.
Step 1: Setup Environment (.build debian package → before_script)
# We're using a Debian testing image (default: image: debian:testing)
# Add arm64 architecture support (required for cross-compilation tools)
dpkg --add-architecture arm64
(.gitlab-ci.yml: before_script in .build debian package)
Step 2: Update & Install Build Dependencies
# Update package lists
apt update
# Install necessary packages for building the kernel
apt install -y devscripts \
build-essential \
crossbuild-essential-arm64 \
bc \
bison \
ccache \
flex \
rsync \
kmod \
cpio \
libelf-dev \
libssl-dev \
libssl-dev:arm64
(.gitlab-ci.yml: before_script in .build debian package)
Step 3: Configure ccache (Compiler Cache)
# Prepend ccache directory to PATH (speeds up rebuilds)
export PATH="/usr/lib/ccache:$PATH"
# Show current ccache stats (empty at this point)
ccache -s
(.gitlab-ci.yml: before_script in .build debian package)
Step 4: Set Build Variables
At this point, the job .build debian package has these variables set:
ARCH=amd64 # Default for this job
DEFCONFIG=defconfig # Config target
CCACHE_BASEDIR=$CI_PROJECT_DIR # Project directory
CCACHE_DIR=$CI_PROJECT_DIR/ccache # Cache location
(.gitlab-ci.yml: variables in .build debian package)
I am only interested in how this kernel is built, please explain it to me, step by step as if I was building it in a terminal session. Reference the yml file for each shell command (or anything else done)
For build arm64 debian package, the variables are overridden:
ARCH=arm64 # Overridden for arm64 build
CROSS_COMPILE=aarch64-linux-gnu- # Cross-compiler prefix
ADDITIONAL_BUILD_CMD="KBUILD_IMAGE=arch/arm64/boot/Image" # Extra make flag
(.gitlab-ci.yml: variables in build arm64 debian package)
Step 5: Generate Default Config
# Generate the default kernel config for the target architecture
make $DEFCONFIG
(.gitlab-ci.yml: script in .build debian package)
Step 6: Customize Kernel Config (amd64 only)
Only for amd64 build (.build debian package job):
# Enable specific kernel features/modules using ./scripts/config
./scripts/config -e WLAN -e WLAN_VENDOR_BROADCOM -m BRCMUTIL -m BRCMFMAC \
-e BRCMFMAC_PROTO_BCDC -e BRCMFMAC_PROTO_MSGBUF \
-e BRCMFMAC_USB \
-e WLAN_VENDOR_REALTEK -m RTW89 -m RTW89_CORE \
-e DYNAMIC_DEBUG \
-m RTW89_PCI -m RTW89_8825B -m RTW89_8852BE \
-m BINFMT_MISC \
-m XFS_FS -m EROFS_FS -m F2FS_FS \
-m EXFAT_FS -m ISO9660_FS
(.gitlab-ci.yml: script in .build debian package)
For arm64 (build arm64 debian package job): This step is skipped. The config remains as generated by make defconfig.
Step 7: Build the Kernel & Debian Packages
# Build the kernel with:
# - Parallel jobs (`-j$(nproc)`: uses all CPU cores)
# - Additional build command (only for arm64: `KBUILD_IMAGE=arch/arm64/boot/Image`)
# - Target: `bindeb-pkg` (creates Debian packages)
make -j$(nproc) $ADDITIONAL_BUILD_CMD bindeb-pkg
(.gitlab-ci.yml: script in .build debian package)
amd64: $ADDITIONAL_BUILD_CMD is empty, so the command is make -j$(nproc) bindeb-pkg.arm64: $ADDITIONAL_BUILD_CMD="KBUILD_IMAGE=arch/arm64/boot/Image", so the command is make -j$(nproc) KBUILD_IMAGE=arch/arm64/boot/Image bindeb-pkg.Step 8: Collect Build Artifacts
# Move generated Debian package files (*.changes, *.deb) to ./artifacts/
mkdir artifacts
dcmd mv ../*.changes artifacts/
(.gitlab-ci.yml: script in .build debian package)
The artifacts/ directory now contains:
linux-image-*.deb, linux-headers-*.deb)*.changes file (metadata for the Debian repository)That's it! You've built:
Image target.Both builds produce Debian packages (*.deb files) in the artifacts/ directory, which are saved as CI artifacts for later use (e.g., in the generate tests job).
Quick Recap of Key Differences:
| amd64 Build | arm64 Build | |
|---|---|---|
| Config Customization | Yes (WiFi, filesystems) | No (uses defconfig) |
CROSS_COMPILE | Not used | aarch64-linux-gnu- |
ADDITIONAL_BUILD_CMD | Empty | KBUILD_IMAGE=arch/arm64/boot/Image |
| Target Image | Automatic (determined by bindeb-pkg) | Explicitly Image |
Now, these built kernel packages are ready for:
lava stage).generate tests to create vmlinuz, modules, and DTBs).Let me know if you'd like me to walk through the generate tests or lava stages next!