Skip to main content

Gitlab FAQ

go get 不支持子群组

# 会指向 gitlab.com/random/xyz 而不是 gitlab.com/random/xyz/something
curl "https://gitlab.com/random/xyz/something?go-get=1"

badage

  • https://gitlab.com/%{project_path}/badges/%{default_branch}/pipeline.svg
    • /pipeline.svg
    • /coverage.svg
    • style=flat-square,flat
    • job=karma&key_text=Frontend+Coverage&key_width=130
    • 可能状态 pending, running, passed, failed, skipped, canceled, unknown
  • Pipeline status badge

覆盖度

  • CI/CD 通用设置 - 配置检测 log 的规则
toolconf
go test -covercoverage: \d+.\d+% of statements

覆盖可视化

go install github.com/boumenot/gocover-cobertura@latest
gocover-cobertura < coverage.txt > coverage.xml
test:
script:
- npm install
- npx nyc --reporter cobertura mocha
artifacts:
reports:
cobertura: coverage/cobertura-coverage.xml

手动触发部署

deploy:prod:manually:
extends:
- .deploy
when: manual

2FA SSH 生成恢复码

ssh [email protected] 2fa_recovery_codes

gitlab runner 缓存耗时长

不缓存,不做 git clean -ffdx。非常适用于大仓库或生成非常多文件的时候。

variables:
GIT_STRATEGY: fetch
GIT_CLEAN_FLAGS: none

Docker build cache

Build:
extends: .docker
stage: build
script:
- docker pull $CI_REGISTRY_IMAGE:build || true
- >
docker build
--pull
--cache-from $CI_REGISTRY_IMAGE:build
--tag build-env
-f Dockerfile.build
.
- docker tag build-env $CI_REGISTRY_IMAGE:build
- docker push $CI_REGISTRY_IMAGE:build

RBAC

caution
  • Developer 默认不可以操作保护分支
    • 可配置允许操作

pipeline failed due to the user not being verified

  • 使用共享 Runner
    • 需要用户验证 - 设置信用卡、不会收费
  • 使用自己的 Runner,可以关闭共享
    • Setting -> CICD -> Runner (Expand) -> disable Shared runner.