希望减少 Jenkins 插件和主从维护,统一代码、流水线和制品到 GitLab。迁移难点在 Jenkinsfile 语义、凭据、构建环境和制品传递。
kubectl -n jenkins get configmap -o yaml > jenkins-config.yaml
find $JENKINS_HOME/jobs -name config.xml -maxdepth 3
grep -nE 'sh\(|withCredentials|archiveArtifacts|publish|docker' Jenkinsfile
helm repo add gitlab https://charts.gitlab.io
helm install gitlab-runner gitlab/gitlab-runner \
--namespace gitlab-runner --create-namespace \
--set gitlabUrl=https://gitlab.example.com \
--set runnerRegistrationToken='***'
.gitlab-ci.yml:stages: [build, test, package]
variables:
DOCKER_BUILDKIT: "1"
build:
stage: build
image: maven:3.9-eclipse-temurin-21
script:
- mvn -B clean package
artifacts:
paths: [target/*.jar]
test:
stage: test
image: maven:3.9-eclipse-temurin-21
script:
- mvn -B test
package:
stage: package
image: docker:27
services: [docker:27-dind]
script:
- docker build -t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA .
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
迁移凭据到 GitLab CI/CD Variables,使用 masked/protected。
配置缓存和制品过期时间,避免存储膨胀。
并行运行 Jenkins 和 GitLab CI,对比构建结果后再切换。
withCredentials 文件凭据在 GitLab 中需要转成 File 类型变量。gitlab-runner — Runner 注册和管理gitlab-ci — 流水线配置docker — 镜像构建jenkins — 旧流水线对照