GitLab CI/CD 配置文件(.gitlab-ci.yml)是用于定义自动化构建、测试和部署流程的重要文件。下面是一个基本的 .gitlab-ci.yml 文件示例,用于构建和部署一个简单的应用。

基础结构

stages:
  - build
  - test
  - deploy

before_script:
  - apt-get update -qq && apt-get install -y python3-pip
  - python3 -m pip install -r requirements.txt

build_job:
  stage: build
  script:
    - echo "Building the application..."
  artifacts:
    paths:
      - build/

test_job:
  stage: test
  script:
    - echo "Running tests..."
  only:
    - master

deploy_job:
  stage: deploy
  script:
    - echo "Deploying the application..."
  only:
    - master

详细说明

  • stages: 定义了三个阶段:构建(build)、测试(test)和部署(deploy)。
  • before_script: 在每个阶段之前运行的脚本,例如安装依赖。
  • build_job: 构建阶段的作业,执行构建命令并将构建产物保存到 artifacts。
  • test_job: 测试阶段的作业,仅当分支为 master 时运行。
  • deploy_job: 部署阶段的作业,仅当分支为 master 时运行。

更多信息

想要了解更多关于 GitLab CI/CD 的信息,请访问我们的文档页面

GitLab CI/CD 流程图