How to use gitlab-runner to execute CI?

  1. Download a gitlab-runner docker image
bash 复制代码
docker pull gitlab/gitlab-runner:latest
  1. Run the GitLab Runner Container
bash 复制代码
docker run \
    -v /your-path/gitlab-runner/config:/etc/gitlab-runner \
    -v /your-path/gitlab-runner/cache:/cache \
	-v /var/run/docker.sock:/var/run/docker.sock \
    --name gitlab-runner gitlab/gitlab-runner:latest
  • --name gitlab-runner:设置容器名称。
  • --restart always:设置容器在 Docker 重启后自动启动。
  • -v /your-path/gitlab-runner/config:/etc/gitlab-runner:将本地路径 /your-path/gitlab-runner/config 挂载到容器中的 /etc/gitlab-runner,用来存储 GitLab Runner 的配置文件。
  • -v /var/run/docker.sock:/var/run/docker.sock:挂载 Docker socket,用以支持Docker执行器。
  1. Register a runner
bash 复制代码
docker run -it --rm -v /your-path/gitlab-runner/config:/etc/gitlab-runner gitlab/gitlab-runner register \
  --non-interactive \
  --executor "docker" \
  --docker-image alpine:latest \
  --url "https://your-gitlab.com/" \
  --registration-token "your token from gitlab" \
  --description "runner" \
  --tag-list "runner-01"
  1. config.toml
bash 复制代码
concurrent = 10
check_interval = 0
connection_max_age = "15m0s"
shutdown_timeout = 0

[session_server]
  session_timeout = 1800

[[runners]]
  name = "runner"
  url = "https://your-gitlab.com/"
  id = 1
  token = "your token"
  token_obtained_at = 2024-11-13T06:53:07Z
  token_expires_at = 0001-01-01T00:00:00Z
  executor = "docker"
  [runners.custom_build_dir]
  [runners.cache]
    MaxUploadedArchiveSize = 0
    [runners.cache.s3]
    [runners.cache.gcs]
    [runners.cache.azure]
  [runners.docker]
    tls_verify = false
    #image = "alpine:latest"
    image = "your-harbor.com/base_image/alpine:latest"
    privileged = false
    disable_entrypoint_overwrite = false
    oom_kill_disable = false
    disable_cache = false
    volumes = [
      "/cache",
      #"/your-path/gitlab-runner/npm_cache:/root/.npm",
      "/your-path/gitlab-runner/npm_cache:/tmp/.npm",
      "/your-path/gitlab-runner/nuget_cache:/root/.nuget/packages",
      "/var/run/docker.sock:/var/run/docker.sock",
      "/your-path/gitlab-runner/config/certs:/certs"
      ]
    shm_size = 0
    network_mtu = 0
  1. Stop gitlab-runner
bash 复制代码
docker stop gitlab-runner
docker rm gitlab-runner
相关推荐
DLYSB_21 小时前
DevOps 运维实战:基于 CI/CD 流水线 Webhook 的构建状态物理现场声光反馈架构
运维·ci/cd·devops·报警灯
huameinan狮子2 天前
微服务化的基石——持续集成
大数据·ci/cd·微服务
一次旅行2 天前
act本地预跑GitHub Actions:Python项目完整CI/CD流水线实战
python·ci/cd·github
csdn2015_2 天前
vscode从gitlab拉项目到本地
vscode·gitlab
heimeiyingwang3 天前
【架构实战】Helm Chart 进阶:依赖管理、测试与 CI/CD 集成
ci/cd·架构
龙智DevSecOps解决方案3 天前
Perforce Delphix测试数据管理平台:每月实现数百万次 CI/CD 运行,更快交付高质量软件
ci/cd·devops·tdm·perforce·delphix·企业级数据管理
AOwhisky4 天前
云原生 DevOps 工具链从入门到实战(第二期)——Jenkins安装与基础配置——CICD核心引擎
linux·运维·ci/cd·云原生·jenkins·devops
析数塔5 天前
SleeperGem 技术拆解:恶意 gem 是怎么躲过 CI/CD 扫描的
安全·ci/cd·github
AOwhisky5 天前
AI审AI:GitLab上线AI代码审查,开发者可以松一口气了吗?
人工智能·gitlab
happy_0x3f6 天前
Claude Code 离线安装方案揭秘
ci/cd