GitLab CI/CD 是一个持续集成和持续部署系统,它允许您自动化构建、测试和部署应用程序。
以下是一个简单的 GitLab CI/CD 脚本示例:
stages:
- build
- test
- deploy
variables:
APP_NAME: myapp
build:
stage: build
image: docker:latest
services:
- docker:dind
script:
- docker build -t $APP_NAME .
test:
stage: test
image: node:lts-alpine
script:
- npm install
- npm run test
deploy_staging:
stage: deploy
environment:
name: staging
url: http://staging.example.com/
script:
- echo "Deploying to staging environment"
# add deployment commands here
deploy_production:
stage: deploy
when: manual # only trigger this job manually
environment:
name: production
url: http://example.com/
script:
- echo "Deploying to production environment"
# add deployment commands here
以上脚本定义了三个不同的阶段:构建、测试和部署。在构建阶段中,使用 Docker 构建镜像;在测试阶段中安装依赖并运行测试;最后,在两个不同的环境(暂存和生产)中进行部署。生产环境部署需要手动触发。
该脚本还设置了一些变量,如应用程序名称等。
请注意,这只是一个简单的示例脚本,您需要根据自己的需求进行调整和修改。




