/ GIT

Gitlab ci 部署

安装gitlab-runner

# 移除旧版本仓库
rm /etc/yum.repos.d/runner_gitlab-ci-multi-runner.repo
# 添加 GitLab's 官方仓库
curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.rpm.sh | sudo bash
# 下载最新版 GitLab Runner
yum install gitlab-runner
# 注册gitlab-runner
gitlab-runner register

# 重启
gitlab-runner restart
# 状态
gitlab-runner status
# 修改配置文件
vi /etc/gitlab-runner/config.toml
# 修改gitlab-runner读写权限
chmod -R 777 /home/gitlab-runner

新建实例runner

alt alt alt alt

添加gitlab-ci.yml文件

stages:          # List of stages for jobs, and their order of execution
  - build
  - test
  - deploy

build-job:       # This job runs in the build stage, which runs first.
  only:
   - tags
  stage: build
  tags:
    - be-runner
  script:
    - echo "Compiling the code..."
    - echo "Compile complete."

unit-test-job:   # This job runs in the test stage.
  only:
   - tags
  stage: test    # It only starts when the job in the build stage completes successfully.
  tags:
    - be-runner
  script:
    - echo "Running unit tests... This will take about 60 seconds."
    - sleep 2
    - echo "Code coverage is 90%"

lint-test-job:   # This job also runs in the test stage.
  only:
   - tags
  stage: test    # It can run at the same time as unit-test-job (in parallel).
  tags:
    - be-runner
  script:
    - echo "Linting code... This will take about 10 seconds."
    - sleep 2
    - echo "No lint issues found."

deploy-job:      # This job runs in the deploy stage.
  only:
   - tags
  stage: deploy  # It only runs when *both* jobs in the test stage complete successfully.
  tags:
    - be-runner
  environment: production
  script:
    - echo "Deploying application..."
    - echo "Application successfully deployed."

验证(yaml文件设置的只有在新建标签时才会运行)

alt alt alt alt