Update file .gitlab-ci.yml

This commit is contained in:
Bunny 2025-05-02 09:55:04 +00:00
parent e24ffcedeb
commit 4d0217b191
1 changed files with 27 additions and 47 deletions

View File

@ -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"
- echo "Deploying to production server..."
- scp target/*.jar user@prod-server:/app/
environment:
name: production
url: https://example.com
when: manual
only:
- tags