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 - deploy
variables: variables:
# 定义全局变量 MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository"
DOCKER_IMAGE: "bunny-auth-server:4.0.0"
# 定义在所有作业之前运行的脚本 cache:
before_script: paths:
- echo "Starting CI/CD pipeline" - .m2/repository/
- target/
build-job: build:
stage: build stage: build
image: maven:3.6.3-jdk-11
script: script:
- echo "Compiling the code..." - mvn package -B
- mvn package # 如果是Java项目
# 或 npm run build # 如果是Node.js项目
artifacts: artifacts:
paths: paths:
- target/*.jar # 保存构建产物 - target/*.jar
only:
- master # 只在master分支运行
unit-test: test:
stage: test stage: test
image: maven:3.6.3-jdk-11
script: script:
- echo "Running unit tests..." - mvn test -B
- 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
deploy-staging: deploy-staging:
stage: deploy stage: deploy
script: script:
- echo "Deploying to staging environment" - echo "Deploying to staging server..."
- scp target/*.jar user@staging-server:/app/
environment: environment:
name: staging name: staging
url: https://staging.example.com url: https://staging.example.com
when: manual
only:
- master
test-multiple-versions: deploy-prod:
stage: test stage: deploy
parallel: 5
script: 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