Skip to content

Gitlab CI

Debug mode

Include this in the job definition inside gitlab-ci.yml:

variables:
  CI_DEBUG_TRACE: "true"

Lint .gitlab-ci.yaml

Local only linters

These don't use the /api/v4/ci/lint API endpoint

check-jsonschema

see ../../json.md

Linters that use the Gitlab API

These use the /api/v4/ci/lint API endpoint. One major blocker: CI Lint API support for passing included files in working tree is still open, until this gets solved we can't use the Gitlab CI API with local includes. See also pre-commit check_yaml hook fails on gitlab-ci files for more details.

Pre-commit-gitlabci-lint

  • GitHub
  • Last commit 2024-01
  • Can deal with includes!
  • No Arch/Mise package

Install:

pipx install pre-commit-gitlabci-lint

Setup:

  1. Create an access token with api scope.
  2. Set access token value in an environment variable named GITLAB_TOKEN or GITLABCI_LINT_TOKEN.
  3. Add the projectId for your gitlab project as a command line argument, or set it in the config file.
  4. Adjust the configuration in ~/.config/.gitlabci-lint/config.toml

Usage:

gitlabci-lint -p <project_id>

pre-commit:

repos:
  - repo: https://github.com/bjd2385/pre-commit-gitlabci-lint
    rev: v1.4.0
    hooks:
      - id: gitlabci-lint
      # args: [-b, 'https://custom.gitlab.host.com', '-p', '12345678']

Stale / not working

other pre-commit integrations

Gitlab cli

https://narkoz.github.io/gitlab/

Usage:

gitlab projects '{per_page: 70}' | grep platf

gitlab merge_requests 128162 --json

gitlab merge_request 128162 230544 --json

gitlab create_merge_request 128195 \
  "Don't remove nfs client tools on vagrant" \
  "{source_branch: 'dont_remove_nfs_client_on_vagrant', \
    target_branch: 'develop', target_project_id: 128162}"

Gitlab "Auto Devops"

Auto Devops gitlab-ci.yml

Teraform integration

Golang cacheing

https://docs.gitlab.com/ee/ci/caching/#caching-go-dependencies

Run CI locally

Matrix builds

Issues:

Run job only if artifact exists

Build container images

Buildah

Issues:

Fails to build with vfs driver on kubernets executor, see this failed job example

Multi arch builds

Podman / Buildah

In order to run Buildah in a custom gitlab-runner on Kubernetes, the scheduled runner pods need to run in privileged mode, unfortunately.

First install prerequisites (also on K8s nodes which gitlab-runner schedule pods on):

Debian:

apt install -y podman buildah qemu-user-static

Arch:

sudo pacman -S qemu-user-static qemu-user-static-binfmt

RedHat flavors:

sudo yum install -y podman buildah qemu-user-static

Then you can use the --platform parameter in Gitlab CI:

buildah build --platform linux/arm64/v8,linux/amd64 -t multiarch:latest