From 4d0217b1918b09ffd4ecdb6dd186f07b94cfb3e8 Mon Sep 17 00:00:00 2001 From: Bunny <1319900154@qq.com> Date: Fri, 2 May 2025 09:55:04 +0000 Subject: [PATCH] Update file .gitlab-ci.yml --- .gitlab-ci.yml | 74 ++++++++++++++++++-------------------------------- 1 file changed, 27 insertions(+), 47 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c398f13..e691f06 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,68 +4,48 @@ stages: - deploy variables: - # 定义全局变量 - DOCKER_IMAGE: "bunny-auth-server:4.0.0" + MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository" -# 定义在所有作业之前运行的脚本 -before_script: - - echo "Starting CI/CD pipeline" +cache: + paths: + - .m2/repository/ + - target/ -build-job: +build: stage: build + image: maven:3.6.3-jdk-11 script: - - echo "Compiling the code..." - - mvn package # 如果是Java项目 - # 或 npm run build # 如果是Node.js项目 + - mvn package -B artifacts: paths: - - target/*.jar # 保存构建产物 - only: - - master # 只在master分支运行 + - target/*.jar -unit-test: +test: stage: test + image: maven:3.6.3-jdk-11 script: - - echo "Running unit tests..." - - mvn test - # 或 npm test - -integration-test: - stage: test - script: - - echo "Running integration tests..." - - mvn verify - needs: ["unit-test"] # 依赖unit-test完成 - -deploy-prod: - stage: deploy - script: - - echo "Deploying to production..." - - scp target/*.jar user@production-server:/app/ - when: manual # 需要手动触发 - only: - - master - -build-docker: - stage: build - image: docker:latest - services: - - docker:dind - script: - - docker build -t $DOCKER_IMAGE . - - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY - - docker push $DOCKER_IMAGE + - mvn test -B deploy-staging: stage: deploy script: - - echo "Deploying to staging environment" + - echo "Deploying to staging server..." + - scp target/*.jar user@staging-server:/app/ environment: name: staging url: https://staging.example.com + when: manual + only: + - master -test-multiple-versions: - stage: test - parallel: 5 +deploy-prod: + stage: deploy script: - - echo "Testing with version $CI_NODE_INDEX" \ No newline at end of file + - echo "Deploying to production server..." + - scp target/*.jar user@prod-server:/app/ + environment: + name: production + url: https://example.com + when: manual + only: + - tags \ No newline at end of file